Submission #545615

#TimeUsernameProblemLanguageResultExecution timeMemory
545615AbdelmagedNourNetwork (BOI15_net)C++17
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; vector<vector<int>>adj; vector<int>V; void dfs(int v,int p){ bool flag=1; for(auto&u:adj[v]){ if(u==p)continue; dfs(u,v); flag=0; } if(flag)V.push_back(v); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin>>n; adj.resize(n); for(int i=1;i<n;i++){ int u,v; cin>>u>>v;u--;v--; adj[u].push_back(v); adj[v].push_back(u); } dfs(0,-1); int sz=V.size(); cout<<(sz+1)/2<<"\n"; for(int i=0;i+(sz+1)/2<sz;i++)cout<<V[i]+1<<" "<<V[i+(sz+1)/2]+1<<"\n"; if(sz&1)cout<<V[sz/2]+1<<" 1"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...