# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
102148 | Leonardo_Paes | Network (BOI15_net) | C++11 | 680 ms | 40956 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];
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
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(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
int n=read();
for(int i=1; i<n; i++){
int a, b;
a=read();
b=read();
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... |