This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* Author: Amirrrr
* Created: 24.06.2023
* Why am I so stupid? :c
* Slishkom slab
**/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) x.begin(), x.end()
#define FF first
#define SS second
#define ent "\n"
#define int long long
const int N = 5e5 + 13;
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int maxn = 1e6 + 12;
int n,x,y,used[N];
vector<int>g[N],ord;
void dfs(int v){
used[v]=1;
if(g[v].size()==1){
ord.pb(v);
}
for(auto to:g[v]){
if(!used[to]){
dfs(to);
}
}
}
void gogo (){
cin>>n;
for(int i=1;i<n;i++){
int x,y;cin>>x>>y;
g[x].pb(y),g[y].pb(x);
}
dfs(1);
cout<<(ord.size()+1)/2<<ent;
for(int i=0;i<ord.size()/2;i++){
cout<<ord[i]<<' '<<ord[i+ord.size()/2]<<ent;
}
if(ord.size()%2){
cout<<ord.back()<<' '<<ord[0]<<ent;
}
}
signed main (/*Amir Mirmanov*/){
ios_base::sync_with_stdio(0),cin.tie(0);
int Q=1,test=1;
//freopen("rain.in","r",stdin);
//freopen("rain.out","w",stdout);
//cin>>Q;
while (Q --){
gogo();
}
return 0;
}
Compilation message (stderr)
net.cpp: In function 'void gogo()':
net.cpp:47:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for(int i=0;i<ord.size()/2;i++){
| ~^~~~~~~~~~~~~
net.cpp: In function 'int main()':
net.cpp:57:13: warning: unused variable 'test' [-Wunused-variable]
57 | int Q=1,test=1;
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |