Submission #826008

#TimeUsernameProblemLanguageResultExecution timeMemory
826008Darren0724Network (BOI15_net)C++17
100 / 100
829 ms47572 KiB
#include<bits/stdc++.h> using namespace std; vector<int> ans; vector<vector<int>> adj; void dfs(int k,int pa){ if(adj[k].size()==1){ ans.push_back(k); } for(int j:adj[k]){ if(j==pa){ continue; } dfs(j,k); } } int main(){ int n;cin>>n; adj.resize(n); for(int i=1;i<n;i++){ int a,b;cin>>a>>b;a--;b--; adj[a].push_back(b); adj[b].push_back(a); } dfs(0,0); int m=ans.size(); for(int &j:ans){ j++; } cout<<(m+1)/2<<endl; for(int i=0;i<m/2;i++){ cout<<ans[i]<<' '<<ans[i+m/2]<<endl; } if(m&1){ cout<<ans[0]<<' '<<ans[m-1]<<endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...