This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// in the name of God
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fast() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ff first
#define ss second
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define mk make_pair
#define ppb pop_back
#define endl '\n'
#define pii pair<int, int>
#define sz(x) (int)x.size()
#define file() freopen("input.txt", "r", stdin);
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O4")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx2")
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int mod = 1e9 + 7, maxn = 5e5 + 10, sq = 3163, inf = 1e18 + 10, lg = 25, pp = 4447, modd = 1e9 + 9;
int n;
vector<vector<int>> g(maxn);
vector<int> b;
void dfs(int u = 0, int par = -1){
if(g[u].size() == 1) b.pb(u);
for(int v : g[u]){
if(v != par) dfs(v, u);
}
}
signed main(){
fast();//file();
cin >> n;
for(int i = 1; i < n; ++i){
int u, v; cin >> u >> v;
u--; v--;
g[v].pb(u);
g[u].pb(v);
}
dfs();
int ans = b.size() + 1;
ans /= 2;
cout << ans << endl;
for(int i = 0; i < (b.size() - (b.size() / 2)); ++i){
cout << b[i] + 1 << " " << b[i + (b.size() / 2)] + 1 << endl;
}
}
// Happiness can be found even in the darkest of times,
// if one only remembers to turn on the light.
Compilation message (stderr)
net.cpp: In function 'int main()':
net.cpp:46:19: 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]
46 | for(int i = 0; i < (b.size() - (b.size() / 2)); ++i){
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |