# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
260011 |
2020-08-08T22:48:23 Z |
test2 |
Network (BOI15_net) |
C++14 |
|
2 ms |
2688 KB |
#include<bits/stdc++.h>
using namespace std ;
using ll = long long ;
const int N =1e5 + 7 ;
int n ;
vector<int> adj[N] ;
vector<pair<int , int> > ans ;
int dfs(int x , int p){
int ls = 0;
vector<int> chs ;
for(auto u : adj[x]){
if(u == p)
continue ;
chs.push_back(dfs(u , x)) ;
}
while(chs.size() > 1){
ls = chs.back() ;
int u = chs.back() ; chs.pop_back() ;
int v = chs.back() ;chs.pop_back() ;
ans.push_back({u , v}) ;
}
if(x == 1 && chs.size()){
ans.push_back({x , chs.back() }) ;
}
if(chs.size())
return chs.back() ;
if(ls)return ls ;
return 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) ;
cout<< ans .size() <<"\n" ;
for(auto u : ans){
cout<< u.first<<" " << u.second <<"\n" ;
}
return 0 ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Incorrect |
2 ms |
2688 KB |
Invalid number of links. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Incorrect |
2 ms |
2688 KB |
Invalid number of links. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Incorrect |
2 ms |
2688 KB |
Invalid number of links. |
3 |
Halted |
0 ms |
0 KB |
- |