Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- bool vis[100010];//stores visiting
- vector<vector<pair<long long,long long> > >v(100010);//Adjlist
- long long arr[100010];//stores array A
- long long maxval=-1;//not zero because answer may be 0 and conflict with the not possible case
- long long s;//collect from input,max time to take
- void dfs(long long node,long long val,long long dist){
- if (dist>s)return;//exceed max dist
- if (vis[node]){ //check for cycle
- if (node==1){ //if cycle leads to
- maxval=max(maxval,val);
- }
- return;
- }
- vis[node]=1;
- for (long long i=0;i<v[node].size();i++){
- dfs(v[node][i].first,val+arr[v[node][i].first],dist+v[node][i].second);
- }
- vis[node]=0;
- return;
- }
- int main() {
- long long n,e,i,i1,x,y,w;
- cin>>n>>e>>s;
- for (i=1;i<=n;i++){//1-indexed
- cin>>arr[i];
- }
- for (i=0;i<e;i++){
- cin>>x>>y>>w;
- v[x].push_back({y,w});
- }
- dfs(1,0,0);
- if (maxval!=-1)cout<<maxval<<'\n';
- else cout<<"Mr Beancurd is doomed!!!\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement