제출 #1126999

#제출 시각아이디문제언어결과실행 시간메모리
1126999AgageldiNetwork (BOI15_net)C++20
0 / 100
11 ms14528 KiB
/*
ID: agageld1
LANG: C++17
TASK:
*/
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define N 600005
#define ff first
#define ss second
#define pb push_back
#define sz(s) (int)s.size()
#define rep(c, a, b) for(c = a; c <= b; c++)

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll n, t, out[N], par[N];
vector <int> v[N], ans;

int main () {
	ios::sync_with_stdio(0);cin.tie(0);
	cin >> n;
	for(int i = 1; i < n; i++) {
		int x, y;
		cin >> x >> y;
		par[x] = y;
		v[x].pb(y);
		v[y].pb(x);
		out[x]++;
	}
	for(int i = 1;i<=n;i++) {
		if(sz(v[i]) == 1) ans.pb(i);
	}
	cout << (sz(ans) + 1) / 2 << '\n';
	for(int i = 0; i < sz(ans) - 1; i++) {
		cout << ans[i] << " " << ans[i+1] << '\n';
		i++;
	}
	if(sz(ans) % 2) {
		for(int i = 1; i <= n; i++) {
			if(par[ans[sz(ans)-1]] != i && i != ans[sz(ans) - 1]) {
				cout << i << " " << ans[sz(ans) - 1] << '\n';
				break;
			}
		}
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...