# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
939072 | ezzzay | Network (BOI15_net) | C++14 | 1 ms | 500 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 int long long
#define ff first
#define ss second
#define pb push_back
const int N=3e3+5;
bool vis[N];
vector<int>v[N];
vector<pair<int,int>>rts;
vector<int>vec;
signed main(){
int n;
cin>>n;
for(int i=1;i<n;i++){
int a,b;
cin>>a>>b;
v[a].pb(b);
v[b].pb(a);
rts.pb({a,b});
}
for(int i=1;i<=n;i++){
if(v[i].size()==1)vec.pb(i);
}
cout<<vec.size()/2+vec.size()%2<<endl;
for(int i=0;i<vec.size()-1;i+=2){
cout<<vec[i]<<" "<<vec[i+1]<<endl;
}
if(vec.size()%2==0)return 0;
for(auto a:v[vec[vec.size()-1]]){
vis[a]=1;
}
for(int i=1;i<=n;i++){
if(vis[i]==0){
cout<<i<<" "<<vec[vec.size()-1];
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... |