#include "closing.h"
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define ii pair<int,int>
int n,a,b,k;
vector<vector<ii> >edge;
const int M=1e6+7;
int dist[2][M];
void dfs(int x,int par,int type)
{
for(ii need:edge[x])
{
int node=need.x;
int value=need.y;
if(node==par)continue;
dist[type][node]=dist[type][x]+value;
dfs(node,x,type);
}
}
int Sub1()
{
queue<int>q;
vector<int>source(2);
source[0]=a;
source[1]=b;
for(int type=0; type<=1; type++)dfs(source[type],0,type);
vector<int>que;
for(int i=0; i<=n-1; i++)
{
que.push_back(dist[0][i]);
que.push_back(dist[1][i]);
}
sort(que.begin(),que.end());
int res=k;
int ans=0;
for(int value:que)
{
if(res<value)break;
res-=value;
ans++;
}
return ans;
}
int max_score(int N,int X,int Y,long long K,vector<int>U,vector<int>V,vector<int>W)
{
n=N;
a=X;
b=Y;
k=K;
edge.resize(n);
for(int i=1; i<=N-1; i++)
{
int x=U[i-1];
int y=V[i-1];
int value=W[i-1];
edge[x].push_back({y,value});
edge[y].push_back({x,value});
}
return Sub1();
}
/*int main()
{
int n,x,y,k;
vector<int>U;
vector<int>V;
vector<int>W;
cin>>n>>x>>y>>k;
for(int i=1; i<=n-1; i++)
{
int x;
cin>>x;
U.push_back(x);
}
for(int i=1; i<=n-1; i++)
{
int y;
cin>>y;
V.push_back(y);
}
for(int i=1; i<=n-1; i++)
{
int value;
cin>>value;
W.push_back(value);
}
cout<<max_score(n,x,y,k,U,V,W);
}
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
114 ms |
29372 KB |
1st lines differ - on the 1st token, expected: '451', found: '628' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
600 KB |
1st lines differ - on the 1st token, expected: '3', found: '4' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
600 KB |
1st lines differ - on the 1st token, expected: '3', found: '4' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
600 KB |
1st lines differ - on the 1st token, expected: '3', found: '4' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |