/*
"care a facut teste cu Lattice reduction attack e ciudat"
"linistiti va putin"
- 2023 -
*/
#include<bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
#pragma GCC optimize("Ofast")
#define int long long
using namespace std;
int dp[1000005]; /// dp[u] = costul sa il fortam pe soricel sa se intoarca la u
vector<int> nodes[1000005];
int n,t,m;
void calc(int node, int parent)
{
int mx1,mx2;
mx1=0;
mx2=0;
for (auto x : nodes[node])
{
if (x!=parent)
calc(x,node);
if (dp[x]>mx1)
{
mx2=mx1;
mx1=dp[x];
}
else if (dp[x]>mx2)
{
mx2=dp[x];
}
}
dp[node]=1+mx2+(nodes[node].size()-1-2)+1;
}
signed main()
{
//ifstream fin("secvp.in");
//ofstream fout("secvp.out");
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int u,v,i;
cin >> n >> t >> m;
for (i=1; i<=n-1; i++)
{
cin >> u >> v;
nodes[u].push_back(v);
nodes[v].push_back(u);
}
calc(m,t);
cout << dp[m];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
23900 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
185 ms |
84200 KB |
Output is correct |
2 |
Correct |
163 ms |
78164 KB |
Output is correct |
3 |
Correct |
428 ms |
82328 KB |
Output is correct |
4 |
Correct |
194 ms |
52816 KB |
Output is correct |
5 |
Correct |
458 ms |
82260 KB |
Output is correct |
6 |
Correct |
462 ms |
82256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
23900 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
23900 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |