# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
394750 | Saynaa | Network (BOI15_net) | C++14 | 7 ms | 11980 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;
typedef long long ll;
const int MAXN = 5e5 + 10;
int n;
vector< int > adj[MAXN], ls;
void dfs(int u, int p = -1){
if( adj[u].size() == 1) ls.push_back(u);
for(int i = 0; i < adj[u].size(); i ++){
int v = adj[u][i];
if( v == p) continue;
dfs(v, u);
}
}
int 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, u --, v --;
adj[u].push_back(v), adj[v].push_back(u);
}
dfs(0);
cout << (ls.size() + 1)/2 << '\n';
int pt = ls.size() - 1;
for(int i = 0; i < ls.size()/2; i ++){
cout << ls[i] + 1 << " " << ls[pt] + 1 << '\n';
pt --;
}
if( ls.size() % 2)
cout << ls[ls.size()/2] + 1 << " " << ls[ls.size()/2 - 1] + 1 << '\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... |