# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1024540 |
2024-07-16T07:10:24 Z |
stdfloat |
Torrent (COI16_torrent) |
C++17 |
|
2000 ms |
20636 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<bool> vis;
vector<int> pr;
vector<vector<int>> E;
void dfs_pr(int x, int p = -1) {
pr[x] = p;
for (auto i : E[x]) {
if (i != p) dfs_pr(i, x);
}
}
int dfs(int x) {
vis[x] = true;
vector<int> v;
for (auto i : E[x]) {
if (!vis[i]) v.push_back(dfs(i));
}
sort(v.rbegin(), v.rend());
int mx = 0;
for (int i = 0; i < (int)v.size(); i++) mx = max(mx, v[i] + i + 1);
return mx;
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n, a, b;
cin >> n >> a >> b; a--; b--;
E.assign(n, {});
for (int i = 1; i < n; i++) {
int x, y;
cin >> x >> y;
E[--x].push_back(--y);
E[y].push_back(x);
}
pr.assign(n, 0);
dfs_pr(a);
int cur = pr[b], mn = INT_MAX;
while (cur != -1) {
vis.assign(n, false);
vis[cur] = true;
int x = dfs(b);
vis[cur] = false;
mn = min(mn, max(x, dfs(a)));
cur = pr[cur];
}
cout << mn;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
5 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2036 ms |
20636 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |