# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1067758 |
2024-08-21T02:53:13 Z |
12345678 |
Torrent (COI16_torrent) |
C++17 |
|
328 ms |
24524 KB |
#include <bits/stdc++.h>
using namespace std;
const int nx=3e5+5;
int n, a, b, u, v, dp[nx], res=INT_MAX;
vector<pair<int, int>> d[nx];
pair<int, int> pa[nx];
vector<int> cut;
void dfspa(int u, int p)
{
for (auto [v, idx]:d[u]) if (v!=p) pa[v]={p, idx}, dfspa(v, u);
}
void dfs(int u, int p, int c)
{
dp[u]=0;
vector<int> s;
for (auto [v, idx]:d[u]) if (v!=p&&idx!=c) dfs(v, u, c), s.push_back(dp[v]);
sort(s.begin(), s.end());
reverse(s.begin(), s.end());
for (int i=0; i<(int)s.size(); i++) dp[u]=max(dp[u], i+1+s[i]);
}
int cost(int x)
{
dfs(a, a, x);
dfs(b, b, x);
return max(dp[a], dp[b]);
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>a>>b;
for (int i=1; i<n; i++) cin>>u>>v, d[u].push_back({v, i}), d[v].push_back({u, i});
dfspa(a, a);
int tmp=b;
while (tmp!=a) cut.push_back(pa[tmp].second), tmp=pa[tmp].first;
int l=0, r=cut.size()-1;
while (l<r)
{
int md=(l+r+1)/2;
if (cost(cut[md])<cost(cut[md-1])) l=md;
else r=md-1;
}
cout<<cost(cut[l]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
7516 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
328 ms |
24524 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |