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>
using namespace std;
#define pb push_back
#define F first
#define S second
#define debug(x) cerr<<#x<<" :"<<x<<"\n"
#define all(x) x.begin(),x.end()
//#define pii pair<int,int>
#define FAST ios_base::sync_with_stdio(false), cin.tie(), cout.tie();
//#define int long long
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int maxn = 5e5 + 7;
const int mod = 1e9 + 7;
const int INF = 1e9 + 7;
const int mlog = 20;
const int SQ = 400;
int root;
vector<int> adj[maxn];
vector<int> Leaf;
void dfs(int v,int par = -1)
{
if(adj[v].size() == 1) Leaf.pb(v);
for(int u : adj[v]) if(u != par) dfs(u, v);
}
int main()
{
FAST;
int n;
cin >> n;
for(int i = 1; i < n; i++)
{
int u, v;
cin >> u >> v;
adj[u].pb(v); adj[v].pb(u);
}
root = 1;
dfs(root);
int SZ = (Leaf.size() + 1) >> 1;
cout << SZ << "\n";
for(int i = 0; i < SZ; i++)
cout << Leaf[i] << " " << Leaf[(i + SZ) % Leaf.size()] << "\n";
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... |