제출 #414427

#제출 시각아이디문제언어결과실행 시간메모리
414427bigDuckNetwork (BOI15_net)C++14
100 / 100
530 ms41836 KiB
#include<bits/stdc++.h> using namespace std; #define INIT ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define mp make_pair #define pb push_back #define ft first #define sc second #define ll long long #define pii pair<int, int> #define count_bits __builtin_popcount //#define int ll int t, n, m, k, q, l, r; vector<int> g[500010]; vector<int> leaves; bool v[500010]; void dfs(int s){ v[s]=true; if(g[s].size()==1){ leaves.pb(s); } for(auto u:g[s]){ if(!v[u]){ dfs(u); } } } int32_t main(){ INIT cin>>n; for(int i=1; i<n; i++){ int a, b; cin>>a>>b; g[a].pb(b); g[b].pb(a); } dfs(1); int sz=((int)leaves.size()+1)>>1ll, add=((int) leaves.size())>>1ll ; cout<<sz<<"\n"; for(int i=0; i<sz; i++){ cout<<leaves[i]<<" "<<leaves[i+add]<<"\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...