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>
#define ll long long
using namespace std;
const ll N=2e5+9,M=2e18+9,mod=1e9+7;
ll n,x,y,z;
map<ll,ll>m;
vector<ll>v;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>n;
while(--n)
{
cin>>x>>y;
++m[x],++m[y];
}
for(auto i:m)
{
if(i.second==1)v.push_back(i.first);
}
n=v.size();
cout<<n/2+n%2<<'\n';
for(ll i=1;i<n;i+=2)cout<<v[i]<<' '<<v[i-1]<<'\n';
if(n&1)cout<<v[n-1]<<' '<<v[0];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |