# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
211386 | Fischer | Torrent (COI16_torrent) | C++14 | 306 ms | 23032 KiB |
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;
const int maxn = 3e5 + 10;
bool vis[maxn];
vector<int> g[maxn];
int n, a, b;
int dp[maxn];
int dfs(int x) {
vis[x] = 1;
vector<int> t;
for (int v : g[x]) {
if (vis[v]) continue;
dfs(v);
t.push_back(dp[v]);
}
sort(t.rbegin(), t.rend());
int ans = 0;
for (int i = 0; i < t.size(); ++i) {
ans = max(ans, t[i] + i + 1);
}
dp[x] = ans;
}
int main() {
cin >> n >> a >> b;
for (int i = 1; i <= n-1; ++i) {
int x, y;
cin >> x >> y;
g[x].push_back(y);
}
vis[a] = vis[b] = 1;
dfs(a); dfs(b);
cout << max(dp[a], dp[b]) << endl;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |