제출 #580242

#제출 시각아이디문제언어결과실행 시간메모리
580242Omar_ElgedawyNetwork (BOI15_net)C++14
100 / 100
658 ms53888 KiB
#include <bits/stdc++.h> using namespace std; #define cin(vec) for(auto& i : vec) cin >> i #define cout(vec) for(auto& i : vec) cout << i << " "; cout << "\n"; #define fast ios::sync_with_stdio(0);cin.tie(0); #define loop(i,a,b) for (int i = a; i < b; i++) #define F first #define S second #define pb(n) push_back(n) #define pf(n) push_front(n) #define dci(d) fixed<<setprecision(d) #define sp ' ' #define el '\n' #define all(v) v.begin(),v.end() #define int long long int dx[8]= {0,0,1,-1,-1,1,1,-1}; int dy[8]= {-1,1,0,0,-1,1,-1,1}; int const N=5e5+5,M=1e3+1,Mod=1e9+7; vector<int>adj[N],par[N]; vector<int>leaf; int n; void dfs(int u,int p){ if(adj[u].size()==1)leaf.push_back(u); for(auto v:adj[u]){ if(v!=p)dfs(v,u); } } void testcase(int h){ cin>>n; for(int i=0;i<n-1;i++){ int u,v;cin>>u>>v; adj[u].pb(v); adj[v].pb(u); } dfs(1,-1); // cout(leaf); int sz=leaf.size(); if(sz%2){ cout<<sz/2+1<<el; for(int i=0;i<sz/2;i++){ cout<<leaf[i]<<' '<<leaf[i+sz/2+1]<<el; } cout<<leaf[sz/2]<<' '<<1<<el; } else{ cout<<sz/2<<el; for(int i=0;i<sz/2;i++){ cout<<leaf[i]<<' '<<leaf[i+sz/2]<<el; } } } int32_t main() { // fast testcase(1); // int tc;cin>>tc;for(int i=1;i<=tc;i++)testcase(i); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...