// YoruoniVamp - VTUBE
// Pragma Credit to Discord: pxsithexahydride
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,no-stack-protector,inline-small-functions,inline,unsafe-math-optimizations,omit-frame-pointer,inline-functions-called-once")
#include <bits/stdc++.h>
#pragma GCC target("avx2,fma,popcnt,lzcnt,bmi,bmi2,sse4.2,tune=native")
using namespace std;
#define endl '\n'
#define ll long long
#define ld long double
#define ull unsigned ll
#define cint const int
#define cf const float
cint mxA = 1e6+5, MOD = 1e9+7, INF = 0x3f3f3f3f;
cint d4x[4] = {0, 1, 0, -1}, d4y[4] = {1, 0, -1, 0};
cint d8x[8] = {0, 1, 1, 1, 0, -1, -1, -1}, d8y[8] = {1, 1, 0, -1, -1, -1, 0, 1};
void wait(int ms){
clock_t endwait;
endwait = clock() + ms;
while(clock()<endwait){}
}
int n, m;
vector<vector<int>> adj(int(5e5)+5);
vector<int> deg1;
void dfs(int u, int pre){
// cout << u << ' ' << pre << endl;
if(adj[u].size()==1){
// cout << "DEG1: " << u << endl;
deg1.emplace_back(u);
}
for(auto v: adj[u]){
if(v!=pre){
dfs(v,u);
}
}
}
void solve(){
cin >> n;
for(int i = 1; i <= n-1; i++){
int a, b; cin >> a >> b;
adj[a].emplace_back(b);
adj[b].emplace_back(a);
}dfs(1,0);
// for(auto i: deg1) cout << i << ' '; cout << endl;
cout << (deg1.size()+1)/2 << endl;
for(int i = 0; i < deg1.size()/2; i++){
cout << deg1[i] << ' ' << deg1[i+(deg1.size()/2)] << endl;
}
if(deg1.size()%2) cout << deg1[0] << ' ' << deg1.back();
return;
}
int main(){
cin.tie(nullptr)->sync_with_stdio(0);cout.tie(0);
// freopen("", "r", stdin);
// freopen("", "w", stdout);
int t = 1;
// cin >> t;
while(t--) solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |