# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1032552 | vjudge1 | Network (BOI15_net) | C++17 | 7 ms | 12196 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 ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pld pair<ld, ld>
#define pb push_back
#define fi first
#define se second
#define debug(x) cout << #x << " => " << x << endl
#define all(x) x.begin(),x.end()
vector<int> adj[500010];
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int n;cin>>n;
for(int i=1;i<n;i++)
{
int u,v;cin>>u>>v;
adj[u].pb(v);
adj[v].pb(u);
}
vector<int> v;
for(int i=1;i<=n;i++) if(adj[i].size()==1) v.pb(i);
vector<pii> ans;
for(int i=0;i<v.size()-1;i+=2)
{
ans.pb({v[i],v[i+1]});
}
if(v.size()&1) ans.pb({v.back(),(v.back()==1?2:1)});
cout<<ans.size()<<'\n';
for(auto i : ans) cout<<i.fi<<' '<<i.se<<'\n';
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... |