# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1264655 | mingga | Network (BOI15_net) | C++20 | 0 ms | 328 KiB |
// Author: caption_mingle
#include "bits/stdc++.h"
using namespace std;
#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define ll long long
const int mod = 1e9 + 7;
const int inf = 2e9;
const int N = 5e5 + 7;
int n, deg[N];
signed main() {
cin.tie(0) -> sync_with_stdio(0);
#define task ""
if(fopen(task ".INP", "r")) {
freopen(task ".INP", "r", stdin);
freopen(task ".OUT", "w", stdout);
}
cin >> n;
for(int i = 1; i < n; i++) {
int u, v; cin >> u >> v;
deg[u]++;
deg[v]++;
}
vector<int> vec;
for(int i = 1; i <= n; i++) {
if(deg[i] == 1) vec.pb(i);
}
cout << (sz(vec) + 1) / 2 << ln;
for(int i = 0; i < sz(vec); i+= 2) {
if(i == sz(vec) - 1) cout << vec[i] << ' ' << vec[0] << ln;
else cout << vec[i] << ' ' << vec[i + 1] << ln;
}
cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}
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... |