제출 #76395

#제출 시각아이디문제언어결과실행 시간메모리
76395MrTEKTorrent (COI16_torrent)C++14
0 / 100
171 ms19836 KiB
#include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back #define len(a) (int)a.size() #define fi first #define sc second #define d1(w) cerr<<#w<<":"<<w<<endl; #define d2(w,c) cerr<<#w<<":"<<w<<" "<<#c<<":"<<c<<endl; #define d3(w,c,z) cerr<<#w<<":"<<w<<" "<<#c<<":"<<c<<" "<<#z<<":"<<z<<endl; #define left ind+ind #define right ind+ind+1 #define mid (l+r)/2 #define FAST_IO ios_base::sync_with_stdio(false); #define endl '\n' #define bit __builtin_popcount typedef long long int ll; const int maxn = 620; const long long LINF = 1e18; const int LOG = 31; const int INF = 1e9; const int P = 31; const int N = 3e5 + 5; const int M = 1e6 + 5; const int SQ = 350; const int MOD = 1e9 + 7; typedef long long int lli; typedef pair<int,int> pii; vector <int> ed[N]; int n,a,b,vis[N]; int solve(int cur,int back,int from) { int mx = -1,cnt = 0; for (auto i : ed[cur]) { if (i != back && vis[i] == from) { int temp = solve(i,cur,from); if (mx < temp) { mx = temp; cnt = 1; } else if (mx == temp) { cnt++; } } } if (mx == -1) return 0; return mx + cnt; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // freopen(".gir","r",stdin); // freopen(".cik","w",stdout); cin >> n >> a >> b; for (int i = 1 ; i < n ; i++) { int u,v; cin >> u >> v; ed[u].pb(v); ed[v].pb(u); } queue <pair <int,int> > Q; Q.push(mp(a,a)); Q.push(mp(b,b)); while(len(Q)) { auto temp = Q.front(); Q.pop(); if (vis[temp.fi]) continue; vis[temp.fi] = temp.sc; for (auto i : ed[temp.fi]) Q.push(mp(i,temp.sc)); } cout << max(solve(a,-1,a),solve(b,-1,b)) << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...