# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
639382 | 3omar_ahmed | Network (BOI15_net) | C++17 | 7 ms | 11988 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.
/**
* author: 3omar_ahmed
* date: 09-09-2022
* Expert When :)
*/
#include <bits/stdc++.h>
using namespace std ;
#define int long long
#define endl '\n'
#define all(a) a.begin() , a.end()
#define alr(a) a.rbegin() , a.rend()
int n ;
vector < vector < int >> adj(500001);
vector < int > a;
void dfs(int node , int par){
if(adj[node].size() == 1){
a.push_back(node);
}
for(auto i : adj[node]){
if(i == par) continue ;
dfs(i , node);
}
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
cin >> n;
for(int i = 1 ; i < n ; i++){
int u , v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(1 , 0);
// for(auto i : a) cout << i << ' ';
// cout << endl;
cout << ((int)(a.size()) + 1) / 2 << endl;
for(int i = 1 ; i < a.size() ; i += 2){
cout << a[i - 1] << ' ' << a[i] << endl;
}
if((int)(a.size()) % 2 == 0) return 0;
int val = a.back();
set < int > s ;
for(int i = 1 ; i <= n ; i++){
if(count(all(adj[val]),i))
continue ;
val = i ;
break ;
}
cout << a.back() << ' ' << val << endl;
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... |