# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
102146 | Leonardo_Paes | Network (BOI15_net) | C++11 | 1099 ms | 47592 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;
const int MAXN = 5e5 + 100;
int v[MAXN], cnt;
vector<int> grafo[MAXN];
void dfs(int u, int p)
{
for (int i=0; i<grafo[u].size(); i++){
int v = grafo[u][i];
if (v == p) continue;
dfs(v, u);
}
if (grafo[u].size() == 1) v[++cnt] = u;
}
int main(){
int n;
cin >> n;
for(int i=1; i<n; i++){
int a, b;
cin >> a >> b;
grafo[a].push_back(b);
grafo[b].push_back(a);
}
for(int i=1; i<=n; i++){
if(grafo[i].size()>1){
dfs(i, 0);
break;
}
}
int ans = (cnt+1)/2;
cout << ans << "\n";
for(int i=1; i<ans; i++){
cout << v[i] << " " << v[i+ans] << "\n";
}
if(cnt&1){
cout << v[ans] << " " << v[1] << "\n";
}
else{
cout << v[ans] << " " << v[cnt];
}
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... |