Submission #24942

#TimeUsernameProblemLanguageResultExecution timeMemory
24942RezwanArefin01Network (BOI15_net)C++14
0 / 100
0 ms13736 KiB
//Bismillahir Rahmanir Rahim #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> ii; const int maxn = 5e5; vector<int> adj[maxn], lef; void dfs(int u, int par){ int cnt = 0; for(int v : adj[u]) if(v - par){ cnt++, dfs(v, u); } if(!cnt) lef.push_back(u); } int main(int argc, char const *argv[]) { #ifdef LOCAL_TESTING freopen("in", "r", stdin); #endif int n; cin>>n; for(int i=0; i<n-1; i++) { int u, v; cin>>u>>v; adj[u].push_back(v); adj[v].push_back(u); } for(int i=1; i<=n; i++) if(adj[i].size() > 1) { dfs(i, 0); break; } int sz = int((lef.size()+1)/2); cout<<sz<<endl; for(int i=0; i<sz; i++) { cout<<lef[i]<<" " << lef[i + sz/2]<<endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...