// #include "closing.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
vector<vector<pair<int,int>>>g;
vector<bool>vis;
set<ll>dis;
ll dfs(int p,int v,ll k,ll curr){
for(auto i:g[v]){
if(i.first==p || vis[i.first])continue;
if(i.second+curr>k)break;
vis[i.first]=1;
dis.insert(curr+i.second);
dfs(v,i.first,k,curr+i.second);
}
}
int max_score(int N, int X, int Y, long long K,vector<int> U, vector<int> V, vector<int> W)
{
int n=N;
dis.clear();
vis.resize(n,0);
g.resize(n,vector<pair<int,int>>());
for(int i=0;i<n;i++){
g[U[i]].pb({V[i],W[i]});
g[V[i]].pb({U[i],W[i]});
}
dfs(X,X,K,0);
dfs(Y,Y,K,0);
ll ans=0;
for(auto i:dis){
if(i>K)break;
ans++;
K-=i;
}
return ans+2;
}
Compilation message
closing.cpp: In function 'long long int dfs(int, int, long long int, long long int)':
closing.cpp:18:1: warning: no return statement in function returning non-void [-Wreturn-type]
18 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
90 ms |
49812 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |