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>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > ordered_set ;
#define int long long
#define F first
#define S second
#define rep(i , j , n ) for(int i = j ;i < n; i++ )
#define FOR(i , n ) rep(i ,0 , n )
#define sz size()
#define pb push_back
#define all(x) x.begin() , x.end()
#define vi vector<int>
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define cans cout<<ans<<endl;
#define forx(i, x) for(auto &i : x)
#define fast
#define pii pair<int ,int >
#define endl "\n"
#define sp ' '
#define test int t ; cin >> t ; while(t--)
const int N = 300 ;
const int inf = 1e15 ;
int n ;
main()
{
cin >> n ;
vi v[n+22] ;
FOR(i ,n-1 ) {
int a , b; cin >> a >> b;
v[a].pb(b) ;
v[b].pb(a) ;
}
vi leaves ;
rep(i , 1 , n + 1 ) {
if(v[i].sz == 1 ) {
leaves.pb(i) ;
}
}
int ans = leaves.sz+1 ;
ans/=2 ; cout<<ans<<endl;
int sz1 = leaves.sz ;
// leaves.pb();
if(sz1&1){while(1){}}
FOR(i , sz1 ) {
cout<<leaves[i]<<" " << leaves[i+1] << endl;
i ++ ;
}
// if(sz1&1)cout<<leaves[sz1-1] << " " << leaves[0]<<endl;
return 0 ;
}
Compilation message (stderr)
net.cpp:28:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
28 | main()
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |