제출 #402848

#제출 시각아이디문제언어결과실행 시간메모리
402848bigDuckNetwork (BOI15_net)C++14
0 / 100
1 ms384 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, a[300010], q, l, r; int dg[500010]; int32_t main(){ INIT cin>>n; for(int i=1; i<n; i++){ int u, v; cin>>u>>v; dg[u]++; dg[v]++; } vector<int> v; for(int i=1; i<=n; i++){ if(dg[i]==1){ v.pb(i); } } vector<pii> res; int lt=0; while(v.size()>0){ if(v.size()==1){ res.pb({lt, v.back()}); v.pop_back(); } else{ lt=v.back(); v.pop_back(); res.pb({lt, v.back()}); v.pop_back(); } } cout<<res.size()<<"\n"; for(auto pr:res){ cout<<pr.ft<<" "<<pr.sc<<"\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...