This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
vector<int> sc[1000006];
long long solve(int w, int f)
{
priority_queue<int> k;
for (auto i : sc[w])
{
if (i == f)
continue;
k.push(solve(i, w));
}
while (k.size() < 2)
k.push(0);
k.pop();
return sc[w].size() - 1 + k.top();
}
int main()
{
ios_base::sync_with_stdio(0);
int n, m, k;
cin >> n >> m >> k;
for (int i = 1; i < n; i++)
{
int a, b;
cin >> a >> b;
sc[a].push_back(b);
sc[b].push_back(a);
}
cout << solve(k, 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... |