Submission #394601

#TimeUsernameProblemLanguageResultExecution timeMemory
394601Nima_NaderiNetwork (BOI15_net)C++14
100 / 100
496 ms55108 KiB
//In the name of GOD #include<bits/stdc++.h> using namespace std; typedef long long ll; const ll MXN = 5e5 + 10; ll n, rt, lf; ll d[MXN]; vector<ll> adj[MXN], L; void dfs(ll u, ll par){ if(d[u] == 1){ L.push_back(u), lf ++; } for(auto v : adj[u]){ if(v != par) dfs(v, u); } } int main(){ ios::sync_with_stdio(0);cin.tie(0); cout.tie(0); cin >> n; for(int i = 1; i < n; i ++){ ll u, v; cin >> u >> v; d[u] ++, d[v] ++; adj[u].push_back(v), adj[v].push_back(u); } for(int i = 1; i <= n; i ++) if(d[i] > 1) rt = i; dfs(rt, 0); cout << (lf + 1) / 2 << '\n'; for(int i = 0; i < lf - lf / 2; i ++){ cout << L[i] << ' ' << L[i + lf / 2] << '\n'; } return 0; } // N.N_2004 // THIS IS THE PAYOFF
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...