This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
"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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |