#include "closing.h"
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>>a[200001];
void dfs(int x, long long int d, long long int dist[], bool visited[])
{
visited[x]=1;
dist[x]=d;
for(int i=0; i<a[x].size(); i++)
{
if(!visited[a[x][i].first])
{
dfs(a[x][i].first, d+a[x][i].second, dist, visited);
}
}
}
int max_score(int N, int X, int Y, long long K, std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
int n=N, x=X, y=Y;
long long k=K;
for(int i=0; i<n-1; i++)
{
a[U[i]].push_back({V[i], W[i]});
a[V[i]].push_back({U[i], W[i]});
}
bool visited[n];
memset(visited, 0, sizeof(visited));
long long int dist1[n], dist2[n];
dfs(x, 0, dist1, visited);
memset(visited, 0, sizeof(visited));
dfs(y, 0, dist2, visited);
long long int dist[2*n];
int j=0, j1=n;
for(int i=0; i<n; i++)
{
dist[j]=dist1[i];
dist[j1]=dist2[i];
j++; j1++;
}
sort(dist, dist+2*n);
int rez=0;
long long kk=0;
for(int i=0; i<2*n; i++)
{
kk+=dist[i];
if(kk<=k)
rez++;
else
break;
}
return rez;
}
Compilation message
closing.cpp: In function 'void dfs(int, long long int, long long int*, bool*)':
closing.cpp:10:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
10 | for(int i=0; i<a[x].size(); i++)
| ~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
7004 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
123 ms |
26932 KB |
Output is correct |
2 |
Correct |
123 ms |
32848 KB |
Output is correct |
3 |
Incorrect |
170 ms |
14420 KB |
2nd lines differ - on the 1st token, expected: '38', found: '45' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4952 KB |
Output is correct |
2 |
Incorrect |
1 ms |
5136 KB |
1st lines differ - on the 1st token, expected: '30', found: '24' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4952 KB |
Output is correct |
2 |
Incorrect |
1 ms |
5136 KB |
1st lines differ - on the 1st token, expected: '30', found: '24' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4952 KB |
Output is correct |
2 |
Incorrect |
1 ms |
5136 KB |
1st lines differ - on the 1st token, expected: '30', found: '24' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
7004 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
7004 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
7004 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
7004 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
7004 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |