Submission #80949

#TimeUsernameProblemLanguageResultExecution timeMemory
80949farukkastamonudaTorrent (COI16_torrent)C++14
100 / 100
630 ms51328 KiB
#include <bits/stdc++.h> #define fi first #define se second #define lo long long #define inf 1000000000 #define md 1000000007 #define li 300005 #define mp make_pair #define pb push_back using namespace std; int n, a, b, x, y, tut; vector<int> v[li], tr, all; pair<int, int> temp; void process(){ for(int i = 0; i < (int)tr.size(); i ++){ all.pb(tr[i]); } } void dfs1(int node, int ata){ tr.pb(node); if(node == b){ process(); return ; } for(int i = 0; i < (int)v[node].size(); i ++){ int go = v[node][i]; if(go == ata) continue; dfs1(go, node); } tr.pop_back(); } int dfs(int node, int ata, int durum){ vector<int> res; for(int i = 0; i < (int)v[node].size(); i ++){ int go = v[node][i]; if(go == ata || (durum == 0 && go == all[tut + 1])) continue; if(durum == 1 && go == all[tut]) continue; res.pb(dfs(go, node, durum)); } sort(res.begin(), res.end(), greater<int>()); int sure=0; for(int i = 0 ; i < (int)res.size(); i ++){ int go = res[i]; sure=max(sure, go + i + 1); } return sure; } pair< int, int > solve(int val){ tut = val; return mp(dfs(a, 0, 0), dfs(b, 0, 1)); } int main(){ scanf("%d %d %d", &n, &a, &b); for(int i = 1; i < n; i ++){ scanf("%d %d", &x, &y); v[x].pb(y); v[y].pb(x); } dfs1(a, 0); int ans = 1000 * 1000 * 1000; int bas = 0, son = (int)all.size() - 2; while(bas <= son){ int mid = (bas + son) / 2; temp = solve(mid); ans = min(ans, max(temp.fi, temp.se)); if(temp.fi <= temp.se) bas = mid + 1; else son = mid - 1; } temp = solve(max(son,0)); ans = min(ans, max(temp.fi, temp.se)); printf("%d\n", ans); return 0; }

Compilation message (stderr)

torrent.cpp: In function 'int main()':
torrent.cpp:53:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d", &n, &a, &b);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
torrent.cpp:55:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &x, &y);
   ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...