제출 #24943

#제출 시각아이디문제언어결과실행 시간메모리
24943RezwanArefin01Network (BOI15_net)C++14
63 / 100
783 ms31984 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){ for(int v : adj[u]) if(v - par) dfs(v, u); if(adj[u].size() == 1) 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 + (lef.size()/2)]<<endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...