| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 765455 | vjudge1 | Network (BOI15_net) | C++17 | 398 ms | 42312 KiB |
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>
#define int long long
#define ull unsigned long long
#define mps make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define sz(x) (x).size()
#define all(x) (x).begin(), (x).end()
#define booster ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fopen(s) freopen(s".in","r",stdin);freopen(s".out","w",stdout)
using namespace std;
const int N = 5e5 + 123;
int n;
vector <int> v,g[N];
vector <pair<int,int>> pr;
bool used[N];
void dfs(int to){
used[to] = true;
if(sz(g[to]) == 1){
v.pb(to);
}
for(auto i : g[to]){
if(!used[i]){
dfs(i);
}
}
}
signed main()
{
booster
cin >> n;
for(int i = 1; i <= n - 1; i++) {
int x,y;
cin >> x >> y;
g[x].pb(y);
g[y].pb(x);
}
dfs(1);
cout << (sz(v) + (sz(v) % 2)) / 2 << '\n';
for(int i = 0; i < sz(v) / 2; i++){
cout << v[i] << ' ' << v[i + sz(v) / 2] << '\n';
}
if(sz(v) % 2 == 1){
cout << v[0] << ' ' << v[sz(v) - 1] << '\n';
}
return 0;
}
/*
1 2 3 4 5
0 1 2 3 4
*/Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
