Submission #474554

#TimeUsernameProblemLanguageResultExecution timeMemory
474554hoangtung_proTorrent (COI16_torrent)C++14
100 / 100
439 ms24660 KiB
#include<bits/stdc++.h> #define endl '\n' #define fi first #define se second #define pb push_back #define bit(s, i) (s & (1<<i)) #define rall(v) v.rbegin(), v.rend() using namespace std; const int N = 3e5 + 5; const int mod = 1e9+7; typedef long long ll; typedef pair < int, int > ii; int n, A, B, dp[N]; vector < int > adj[N]; vector < int > tung, goo; void dfs(int u, int p) { tung.pb(u); if(u == B) goo = tung; for(int v : adj[u]) if(v != p) dfs(v, u); tung.pop_back(); } void Dfs(int u, int p, int dap) { dp[u] = 0; if(u == dap) return; for(int v : adj[u]) if(v != p && v != dap) Dfs(v, u, dap); tung.clear(); for(int v : adj[u]) if(v != p && v != dap) tung.pb(dp[v]); sort(rall(tung)); for(int i=0;i<tung.size();++i) dp[u] = max(dp[u], tung[i] + i + 1); } int main() { ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); // freopen("trash.inp","r",stdin); // freopen("trash.out","w",stdout); cin >> n >> A >> B; for(int i=1, u, v;i<n;++i) { cin >> u >> v; adj[u].pb(v); adj[v].pb(u); } dfs(A, 0); Dfs(A, 0, 0); int res = dp[A]; int l = 0, r = goo.size() - 2; while(l <= r) { int mid = (l + r) / 2; Dfs(A, 0, goo[mid + 1]); Dfs(B, 0, goo[mid]); res = min(res, max(dp[A], dp[B])); if(dp[A] < dp[B]) l = mid + 1; else r = mid - 1; } cout << res; }

Compilation message (stderr)

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