Submission #1127045

#TimeUsernameProblemLanguageResultExecution timeMemory
1127045AgageldiNetwork (BOI15_net)C++20
0 / 100
10 ms14408 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define N 600005 #define ff first #define ss second #define pb push_back #define sz(s) (int)s.size() #define rep(c, a, b) for(c = a; c <= b; c++) //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); ll n, t = -1, out[N], mx, nd; vector <int> v[N], answer; vector <pair<int,int>> ans; map <int,int> vis, vip; void solve(int x,int jog, int cnt) { vis[x] = 1; for(auto i:v[x]) { if(vis[i]) continue; solve(i,jog,cnt + 1); } if(sz(v[x]) == 1 && vip[x] == 0 && cnt > mx) { mx = cnt; nd = x; } } int main () { ios::sync_with_stdio(0);cin.tie(0); cin >> n; for(int i = 1; i < n; i++) { int x, y; cin >> x >> y; v[x].pb(y); v[y].pb(x); } for(int i = 1;i<=n;i++) { if(sz(v[i]) == 1) answer.pb(i); } cout << (sz(answer) + 1) / 2 << '\n'; if(sz(answer) % 2) { t = answer[sz(answer)- 1]; answer.pop_back(); } for(auto i : answer) { if(vip[i]) continue; vis.clear(); mx = nd = 0; vip[i] = 1; solve(i, i, 0); vip[nd] = 1; cout << i << " " << nd << '\n'; } if(t == -1) return 0; cout << t << " " << answer[0] << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...