제출 #638397

#제출 시각아이디문제언어결과실행 시간메모리
638397xadNetwork (BOI15_net)C++14
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> using namespace std ; #define nn "\n" #define x_x ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define intt int t; cin>>t; while(t--) #define emp emplace_back #define mod 1000000007 #define all(v) v.begin(), v.end() #define sz(x) (int)x.size() //#define a first //#define b second typedef long long ll; int main() { x_x int n; cin>>n; vector<int>adj[n+2]; vector<pair<int,int>>v,ch; int p[n+2]; for(int i=1,x,y; i<n; i++)cin>>x>>y, adj[x].emp(y), adj[y].emp(x),p[x]=y,p[y]=x; for(int i=1; i<=n; i++) if(sz(adj[i])==1) { ch.push_back({p[i],i}); } sort(all(ch)); if(ch[0].first==ch.back().first) { cout<<sz(ch)/2+(sz(ch)%2)<<nn; for(int i=0; i<sz(ch)-1; i+=2)cout<<ch[i].second<<' '<<ch[i+1].second<<nn; if(sz(ch)%2)cout<<ch[0].second<<' '<<ch.back().second; } else { for(int i=0,j=0; i<sz(ch); i++) { if(!ch[i].first)continue; while(ch[j].first==ch[i].first)j=(j+1)%sz(ch); v.push_back({ch[i].second,ch[j].second}); ch[i].first=ch[j].first=0; j=(j+1)%sz(ch); } cout<<sz(v)<<nn; for(auto i:v)cout<<i.first<< ' '<<i.second<<nn; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...