#include "closing.h"
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<vector<pair<int,ll> > >g;
vector<vector<ll> >d;
vector<int>p;
void dfs(int v,int pr,int j){
p[v]=pr;
for (auto [to,w]:g[v]){
if (to==pr) continue;
d[j][to]=d[j][v]+w;
dfs(to,v,j);
}
}
int max_score(int N, int X, int Y, long long K,
std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
g.clear();
d.clear();
p.clear();
g.resize(N+1);
d.resize(2,vector<ll>(N+1,0));
p.resize(N+1,-1);
for (int i=0;i<N-1;i++){
g[U[i]].push_back({V[i],W[i]});
g[V[i]].push_back({U[i],W[i]});
}
{
d[0][X]=0;
dfs(X,-1,0);
}
{
d[1][Y]=0;
dfs(Y,-1,1);
}
set<pair<ll,int> >st;
vector<pair<ll,int> >v;
for (int i=0;i<N;i++){
st.insert({min(d[0][i],d[1][i]),i});
v.push_back({max(d[0][i],d[1][i]),i});
}
sort(v.begin(),v.end());
ll sum=0ll;
int ans=2;
int cnt1=0;
for (auto [dist,i]:v){
int cnt2=0;
ll sum2=sum;
for (auto cur:st){
sum2+=cur.first;
if (sum2>K) break;
cnt2++;
}
ans=max(ans,cnt1+cnt2);
sum+=dist;
st.erase({min(d[0][i],d[1][i]),i});
cnt1++;
}
if (sum<=K){
ans=2*N;
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
231 ms |
48436 KB |
1st lines differ - on the 1st token, expected: '451', found: '199999' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '30', found: '19' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '30', found: '19' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '30', found: '19' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '30', found: '19' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '30', found: '19' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '30', found: '19' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '30', found: '19' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '30', found: '19' |
4 |
Halted |
0 ms |
0 KB |
- |