제출 #656037

#제출 시각아이디문제언어결과실행 시간메모리
656037Mohammad_ParsaNetwork (BOI15_net)C++14
100 / 100
601 ms41544 KiB
/* in the name of allah */ #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define F first #define S second #define mk make_pair const int N=5e5+7; vector<int>vec[N],barg; void dfs(int v,int p){ if(vec[v].size()==1) barg.pb(v); for(auto u:vec[v]){ if(u!=p) dfs(u,v); } } int main(){ ios:: sync_with_stdio(0),cin.tie(0),cout.tie(0); int n; cin>>n; int u,v; for(int i=0;i<n-1;i++){ cin>>u>>v; vec[v].pb(u); vec[u].pb(v); } if(n==2){ cout<<1<<endl<<1<<" "<<2; return 0; } for(int i=1;i<=n;i++){ if(vec[i].size()!=1){ dfs(i,i); break; } } int x=barg.size()/2+(barg.size()%2); cout<<x<<endl; for(int i=0;i<x;i++){ cout<<barg[i]<<" "<<barg[(i+x)%barg.size()]<<endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...