# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
280159 | test2 | Network (BOI15_net) | C++14 | 561 ms | 83056 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>
#define I inline void
using namespace std ;
using ll = long long ;
using ld = long double ;
const int N = 2e6 + 7 ;
// How interesting!
int n;
vector<int> adj[N] ;
vector<pair<int , int> > ans ;
vector<int> leafs ;
I dfs(int x, int p){
for(auto u : adj[x]){
if(u == p)
continue ;
dfs(u , x) ;
}
if(adj[x].size() == 1)
leafs.push_back(x) ;
}
int main(){
ios_base::sync_with_stdio(0) ;
cin.tie(0) ;
//freopen("in.in", "r" , stdin) ;
cin >> n ;
for(int i = 0 ;i < n -1 ;i ++){
int u , v;
cin >> u >> v ;
adj[u].push_back(v) ;
adj[v].push_back(u) ;
}
dfs(1 , 1) ;
if(leafs.size() & 1){
cout<< (int) leafs.size() / 2 + 1<<"\n" ;
for(int i = 0 ;i < leafs.size() / 2 ; i++){
cout<< leafs[i] <<" " << leafs[i + leafs.size() / 2 + 1] <<"\n" ;
}
cout<< leafs[leafs.size() / 2] <<" " << 1 <<"\n" ;
}
else{
cout<< (int) leafs.size() / 2 <<"\n" ;
for(int i = 0 ;i <(int) leafs.size() / 2 ; i++){
cout<< leafs[i] <<" " << leafs[i + leafs.size() / 2] <<"\n" ;
}
}
return 0 ;
}
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... |