# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
716597 | Spade1 | Network (BOI15_net) | C++14 | 1 ms | 324 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.
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
//#include <grader.h>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ll long long
#define ld long double
#define st first
#define nd second
#define pb push_back
#define INF INT_MAX
#define db double
using namespace std;
const int N = 5e5 + 10;
int cnt[N];
void solve() {
int n; cin >> n;
for (int i = 1; i < n; ++i) {
int u, v; cin >> u >> v;
cnt[u]++, cnt[v]++;
}
vector<int> v;
for (int i = 1; i <= n; ++i) if (cnt[i]==1) v.pb(i);
cout << (v.size()+1)/2 << '\n';
for (int i = 0; i < v.size(); ++i) {
if (i==v.size()-1) {
cout << v[i] << " " << v[0] << '\n';
}
else {
cout << v[i] << " " << v[++i] << '\n';
}
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(NULL);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
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... |