Submission #1067731

#TimeUsernameProblemLanguageResultExecution timeMemory
106773112345678Torrent (COI16_torrent)C++17
0 / 100
24 ms16208 KiB
#include <bits/stdc++.h> using namespace std; const int nx=1e5+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()); for (int i=0; i<s.size(); i++) dp[u]=max(dp[u], i+1+s[i]); } 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; for (auto x:cut) { dfs(a, a, x); dfs(b, b, x); res=min(res, max(dp[a], dp[b])); } cout<<res; }

Compilation message (stderr)

torrent.cpp: In function 'void dfs(int, int, int)':
torrent.cpp:23:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for (int i=0; i<s.size(); i++) dp[u]=max(dp[u], i+1+s[i]);
      |                   ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...