#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
int const MAXN=2e5+10;
vector<pair<int,int>>nei[MAXN]={};
long long dis[2][MAXN]={};
bool uni=0;
vector<pair<long long,int>>d[2];
void dfs(int u,int p=-1)
{
d[uni].push_back({dis[uni][u],u});
for (auto [i,w]:nei[u])
{
if (i==p)
continue;
dis[uni][i]=dis[uni][u]+w;
dfs(i,u);
}
}
int max_score(int N, int X, int Y, long long K, vector<int> U,vector<int> V, vector<int> W)
{
for (int i=0;i<N;i++)
nei[i]={},dis[0][i]=dis[1][i]=0;
d[0]=d[1]={};
uni=0;
for (int i=0;i<N-1;i++)
{
nei[U[i]].push_back({V[i],W[i]});
nei[V[i]].push_back({U[i],W[i]});
}
dfs(X);
uni=1;
dfs(Y);
for (int i=0;i<2;i++)
sort(begin(d[i]),end(d[i]));
int i=0,j=0;
int cnt=0;
while (i<N&&j<N)
{
long long z=1e11;
if (i<N)
z=d[0][i].first;
if (j<N)
z=min(z,d[1][j].first);
if (z>K)
break;
else
K-=z;
if (i<N&&j<N)
{
if (d[0][i].first<d[1][j].first)
{
cnt++;i++;
}
else
{
cnt++;j++;
}
}
else if (i==N)
{
cnt++;
j++;
}
else
cnt++,i++;
}
return cnt;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
7256 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 |
96 ms |
36364 KB |
Output is correct |
2 |
Correct |
126 ms |
42740 KB |
Output is correct |
3 |
Correct |
53 ms |
9808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
7004 KB |
Output is correct |
2 |
Incorrect |
1 ms |
7004 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 |
7004 KB |
Output is correct |
2 |
Incorrect |
1 ms |
7004 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 |
7004 KB |
Output is correct |
2 |
Incorrect |
1 ms |
7004 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 |
2 ms |
7256 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 |
2 ms |
7256 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 |
2 ms |
7256 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 |
2 ms |
7256 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 |
2 ms |
7256 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |