#include <vector>
#include <algorithm>
using namespace std;
struct Arc{int v,d;};
vector<Arc> gr[200000];
long long dist[400001];
long long d;
int nd;
bool fix[200000];
void dfs(int u){
fix[u]=1;
for (int i=0;i<(int)gr[u].size();i++){
int v=gr[u][i].v;
if (!fix[v]) {nd++; d+=gr[u][i].d; dist[nd]=d; dfs(v); d-=gr[u][i].d; }
}
}
int max_score(int N, int X, int Y, long long K,
std::vector<int> U, std::vector<int> V, std::vector<int> W) {
Arc tmp;
for (int i=0;i<N;i++) {gr[i].clear(); fix[i]=0;}
//for (int i=0;i<=2*N;i++) dist[i]=0;
for (int i=0;i<N-1;i++){
tmp.v=V[i]; tmp.d=W[i]; gr[U[i]].push_back(tmp);
tmp.v=U[i]; gr[V[i]].push_back(tmp);
}
d=0; nd=0; dist[0]=0; dfs(X);
for (int i=0;i<N;i++) fix[i]=0;
d=0; nd++; dist[nd]=0;dfs(Y);
sort(dist,dist+nd+1);
int ans=0; long long sum=0;
for (int i=0;i<2*N;i++)
if (sum+dist[i]>K) break;
else {sum+=dist[i]; ans++; }
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
5208 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
94 ms |
23612 KB |
Output is correct |
2 |
Correct |
110 ms |
26708 KB |
Output is correct |
3 |
Correct |
53 ms |
7760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
5212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
5212 KB |
1st lines differ - on the 1st token, expected: '30', found: '24' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
5212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
5212 KB |
1st lines differ - on the 1st token, expected: '30', found: '24' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
5212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
5212 KB |
1st lines differ - on the 1st token, expected: '30', found: '24' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
5208 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
5208 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
5208 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
5208 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
5208 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |