// oooo
/*
har chi delet mikhad bebar ~
gitar o ba khodet nabar! ~
;Amoo_Hasan;
*/
#include<bits/stdc++.h>
//#pragma GCC optimize("O3,no-stack-protector,unroll-loops")
//#pragma GCC target("avx2,fma")
using namespace std;
typedef long long ll;
typedef long double ld;
#define Sz(x) int((x).size())
#define All(x) (x).begin(), (x).end()
#define wtf(x) cout<<#x <<" : " <<x <<endl
constexpr ll inf = 1e18, N = 1e6 + 10, mod = 1e9 + 7, pr = 1000696969;
bool flag = false;
int dp[N];
vector<int> adj[N];
void dfs(int x, int p = 0) {
int tim = 0;
vector<int> vc;
for(auto j : adj[x]) {
if(j == p) continue;
tim++;
dfs(j, x);
vc.push_back(dp[j]);
}
sort(All(vc), greater<int>());
if(tim == 0) {
dp[x] = 0;
return;
}
if(tim == 1) {
dp[x] = 1;
return;
}
dp[x] = tim;
dp[x] += vc[1];
}
int main() {
ios :: sync_with_stdio(0), cin.tie(0);
int n, t, m; cin >>n >>t >>m;
for(int i = 0; i < n - 1; i++) {
int u, v; cin >>u >>v;
adj[u].push_back(v), adj[v].push_back(u);
if(u == t && v == m) flag = true;
if(u == m && v == t) flag = true;
}
assert(flag);
dfs(t);
int ans = dp[m];
vector<int> vc;
for(auto j : adj[t]) {
if(j == m) continue;
vc.push_back(dp[j]);
}
sort(All(vc), greater<int>());
if(Sz(vc) >= 2) ans += vc[1];
ans += Sz(vc);
cout<<ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
29 ms |
48052 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
315 ms |
72356 KB |
Output is correct |
2 |
Correct |
297 ms |
67460 KB |
Output is correct |
3 |
Correct |
726 ms |
73324 KB |
Output is correct |
4 |
Correct |
366 ms |
48396 KB |
Output is correct |
5 |
Correct |
722 ms |
73320 KB |
Output is correct |
6 |
Correct |
748 ms |
73320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
29 ms |
48052 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
29 ms |
48052 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |