# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
765399 | vjudge1 | Network (BOI15_net) | C++17 | 12 ms | 23764 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.
/******************
tree-bends-in-youth
//24///06///2023///
******************/
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
const ll N = 1e6 + 1;
const ll INF = 1e17;
const ll MOD = 1e9 + 7;
vector<int>g[N];
vector <int> l;
map<int,int>used;
int tm;
void dfs(int v){
used[v]=1;
if(g[v].size() == 1)l.pb(v);
for(ll to : g[v]){
if(!used[to]){
dfs(to);
}
}
}
void solve(){
int n;
cin >> n;
for(int i=1;i<n;i++){
int x,y;
cin>>x>>y;
g[x].pb(y);
g[y].pb(x);
}
int r = 0;
for(int i = 1;i <= n;i++){
if(g[i].size() > 1){
r = i;
break;
}
}
dfs(r);
int k = (l.size() + 1) / 2;
cout << k << '\n';
for(int i = 0;i + k < l.size();i++){
cout << l[i] << " " << l[i + k] << '\n';
}
if(k % 2){
cout << l[0] << " " << l[k - 1] << '\n';
}
}
main () {
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("censor.in","r",stdin);
//freopen("censor.out","w",stdout);
ll T = 1;
//cin >> T;
for(ll i = 1;i <= T;i++){
// cout << "Case " << i << ":\n";
solve();
}
}
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... |