Question: include bitsstdch using namespace std string ltrimconst string string rtrimconst string Global variables int n m maxt int ans 0 vectorint beauty u v t
include bitsstdch using namespace std string ltrimconst string string rtrimconst string Global variables int n m maxt int ans 0 vectorint beauty u v t vectorpairint int adj10000 bool vis10000 void dfsint s int currenttime int currentbeauty Check if current time exceeds maximum allowed time if currenttime maxt return Update max beauty if back at hotel node 0 if s 0 ans maxans currentbeauty Explore neighbors for auto neighbor traveltime adjs if visneighbor visneighbor true Mark as visited dfsneighbor currenttime traveltime currentbeauty beautyneighbor visneighbor false Backtrack void solve Build the adjacency list for the graph for int i 0 i m i adjuiemplacebackvi ti adjviemplacebackui ti Undirected graph vis0 true Start from the hotel node 0 dfs0 0 beauty0 Start DFS int main Input reading cin n m maxt beautyresizen for int i 0 i n i cin beautyi uresizem vresizem tresizem for int i 0 i m i cin ui for int i 0 i m i cin vi for int i 0 i m i cin ti Solve the problem solve Output the result cout ans endl return 0 string ltrimconst string str string sstr serasesbegin findifsbegin send not1ptrfunint intisspace return s string rtrimconst string str string sstr serasefindifsrbegin srend not1ptrfunint intisspacebase send return s
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
