#include <bits/stdc++.h>
using namespace std;
#define int int64_t
vector<vector<int>> graph;
int dfs2(int v, int p){
priority_queue<int> pq;
for(auto u:graph[v]){
if(u==p)continue;
int x=dfs2(u,v);
pq.push(x);
}
int sum=0;
int i=0;
while (!pq.empty()){
sum++;
if(i%2)sum+=pq.top();
i++;
pq.pop();
}
return sum;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n,t,m;
cin>>n>>t>>m;
graph.resize(n);
t--;
m--;
for(int i=0;i<n-1;i++){
int a,b;
cin>>a>>b;
a--;
b--;
graph[a].push_back(b);
graph[b].push_back(a);
}
int sol=dfs2(m,t);
cout<<sol<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
438 ms |
62856 KB |
Output is correct |
2 |
Correct |
336 ms |
56596 KB |
Output is correct |
3 |
Incorrect |
858 ms |
61268 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |