# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
824330 | irmuun | Network (BOI15_net) | C++17 | 359 ms | 70976 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll n;
cin>>n;
vector<ll>adj[n+1];
for(ll i=1;i<n;i++){
ll a,b;
cin>>a>>b;
adj[a].pb(b);
adj[b].pb(a);
}
ll mx=0,ind;
for(ll i=1;i<=n;i++){
if(adj[i].size()>mx){
mx=adj[i].size();
ind=i;
}
}
vector<ll>ord;
function <void(ll,ll)> dfs=[&](ll x,ll p){
if(adj[x].size()==1){
ord.pb(x);
}
for(auto y:adj[x]){
if(y!=p){
dfs(y,x);
}
}
};
for(auto x:adj[ind]){
dfs(x,ind);
}
if(ord.size()%2==1){
ord.pb(ord[0]);
}
ll sz=ord.size();
cout<<sz/2<<"\n";
for(ll i=0;i<sz/2;i++){
cout<<ord[i]<<' '<<ord[i+sz/2]<<"\n";
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |