# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1264683 | mingga | Network (BOI15_net) | C++20 | 277 ms | 37112 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, in[N], out[N], timer;
vector<int> g[N];
void dfs(int u, int p) {
in[u] = ++timer;
for(int v : g[u]) {
if(v == p) continue;
dfs(v, u);
}
}
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;
g[u].pb(v);
g[v].pb(u);
}
dfs(1, 0);
vector<int> vec;
int dak = 0;
for(int i = 1; i <= n; i++) {
if(sz(g[i]) == 1) vec.pb(i);
else dak = i;
}
sort(all(vec), [&](int x, int y) {
return in[x] < in[y];
});
cout << (sz(vec) + 1) / 2 << ln;
for(int i = 0; i < sz(vec) / 2; i++) {
cout << vec[i] << ' ' << vec[sz(vec) / 2 + i] << ln;
}
if(sz(vec) & 1) {
cout << vec.back() << ' ' << vec[0] << ln;
}
cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}
컴파일 시 표준 에러 (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... |