# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
41218 | wzy | Network (BOI15_net) | C++14 | 10 ms | 12132 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;
#define F first
#define S second
#define int long long // LEMBRAR DE TROCAR CASO PROBLEMA DE MEMORIA
#define pii pair<int,int>
#define ieps (int) 1e6
#define eps (int) 1e9
#define mp make_pair
#define pb push_back
int n;
vector<int> adj[500005];
vector<int> ans;
int32_t main(){
int n;
cin>>n;
int root = 0;
for(int i = 0 ; i <n - 1; i++){
int x ,y;
cin>>x>>y;
adj[x].pb(y);
adj[y].pb(x);
root = x;
}
for(int i = 1 ; i <=n ; i++){
if(adj[i].size() == 1) ans.pb(i);
}
cout<< (ans.size()/2) + (ans.size()%2) << endl;
for(int i = 0 ; i <( ans.size() / 2 + ans.size()%2) ; i++){
if(i == ans.size()/2 && (ans.size())%2){
cout<<ans[i] <<" " << ans[0]<<endl;
continue;
}
cout<<ans[i] <<" " << ans[ans.size() - i - 1]<<endl;
}
}
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... |