# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
234429 | bharat2002 | Network (BOI15_net) | C++14 | 13 ms | 12160 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.
/*input
8
1 2
2 3
3 4
4 5
3 6
3 7
3 8
*/
#include<bits/stdc++.h>
using namespace std;
const int N=5e5 + 100;
const int mod=1e9 + 7;
#define int long long
const int inf=1e18;
#define pii pair<int, int>
#define f first
#define s second
#define mp make_pair
#define FOR(i, n) for(int i=1;i<=n;i++)
#define TRACE(x) cerr << #x << " = " << x << endl
//Trace prints the name of the variable and the value.
int n;vector<int> adjlist[N];vector<int> nodes;
signed main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
cin>>n;
for(int i=1;i<n;i++)
{
int a, b;cin>>a>>b;adjlist[a].push_back(b);adjlist[b].push_back(a);
}
for(int i=1;i<=n;i++)
{
if(adjlist[i].size()==1) nodes.push_back(i);
}
int ext=1;
if(nodes.back()==ext) ext=n;
int ans=nodes.size();
if(ans%2==1) ans++;ans/=2;
cout<<ans<<endl;
for(int i=0;i<nodes.size()-1;i+=2)
{
cout<<nodes[i]<<" "<<nodes[i+1]<<endl;
}
ans=nodes.size();
if(ans%2==1) cout<<ext<<" "<<nodes.back();
}
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... |