#include "bits/stdc++.h"
using namespace std;
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
cout << a << ' ', abc(b...);
}
template <typename T> void printv(T l, T r) {
while (l != r) cout << *l << " \n"[++l == r];
}
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
return o >> a.first >> a.second;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
return o << '(' << a.first << ", " << a.second << ')';
}
template <typename T> ostream& operator << (ostream& o, vector<T> a) {
bool is = false;
for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;}
return o << '}';
}
#ifdef local
#define test(args...) abc("[" + string(#args) + "]", args)
#else
#define test(args...) void(0)
#endif
using ll = long long;
vector<int> adj[500005];
bool seen[500005];
vector<int> order;
void dfs(int node) {
seen[node] = true;
bool leaf = true;
for (auto nxt : adj[node]) {
if (seen[nxt]) continue;
dfs(nxt);
leaf = false;
}
if (leaf) order.push_back(node);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// freopen("", "r", stdin);
// freopen("", "w", stdout);
int n; cin >> n;
for (int i = 0; i < n-1; i++) {
int a, b; cin >>a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
for (int i = 1; i <= n; i++) {
if (adj[i].size() >= 2) {
dfs(i);
break;
}
}
int s = order.size();
cout << ceil(s / 2.0) << endl;
for (int i = 0; i < (s + 1) /2; i++) {
cout << order[i] << " " << order[min(i + s/2, s-1)] << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
7 ms |
12068 KB |
Output is correct |
3 |
Correct |
6 ms |
12068 KB |
Output is correct |
4 |
Correct |
6 ms |
12064 KB |
Output is correct |
5 |
Correct |
6 ms |
11988 KB |
Output is correct |
6 |
Correct |
6 ms |
11988 KB |
Output is correct |
7 |
Correct |
6 ms |
11988 KB |
Output is correct |
8 |
Correct |
6 ms |
12068 KB |
Output is correct |
9 |
Correct |
6 ms |
11988 KB |
Output is correct |
10 |
Correct |
7 ms |
12044 KB |
Output is correct |
11 |
Correct |
6 ms |
12064 KB |
Output is correct |
12 |
Correct |
6 ms |
11988 KB |
Output is correct |
13 |
Correct |
6 ms |
11988 KB |
Output is correct |
14 |
Correct |
6 ms |
11988 KB |
Output is correct |
15 |
Correct |
6 ms |
11988 KB |
Output is correct |
16 |
Correct |
7 ms |
12132 KB |
Output is correct |
17 |
Correct |
8 ms |
12064 KB |
Output is correct |
18 |
Correct |
6 ms |
12068 KB |
Output is correct |
19 |
Correct |
6 ms |
11988 KB |
Output is correct |
20 |
Correct |
6 ms |
11988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
7 ms |
12068 KB |
Output is correct |
3 |
Correct |
6 ms |
12068 KB |
Output is correct |
4 |
Correct |
6 ms |
12064 KB |
Output is correct |
5 |
Correct |
6 ms |
11988 KB |
Output is correct |
6 |
Correct |
6 ms |
11988 KB |
Output is correct |
7 |
Correct |
6 ms |
11988 KB |
Output is correct |
8 |
Correct |
6 ms |
12068 KB |
Output is correct |
9 |
Correct |
6 ms |
11988 KB |
Output is correct |
10 |
Correct |
7 ms |
12044 KB |
Output is correct |
11 |
Correct |
6 ms |
12064 KB |
Output is correct |
12 |
Correct |
6 ms |
11988 KB |
Output is correct |
13 |
Correct |
6 ms |
11988 KB |
Output is correct |
14 |
Correct |
6 ms |
11988 KB |
Output is correct |
15 |
Correct |
6 ms |
11988 KB |
Output is correct |
16 |
Correct |
7 ms |
12132 KB |
Output is correct |
17 |
Correct |
8 ms |
12064 KB |
Output is correct |
18 |
Correct |
6 ms |
12068 KB |
Output is correct |
19 |
Correct |
6 ms |
11988 KB |
Output is correct |
20 |
Correct |
6 ms |
11988 KB |
Output is correct |
21 |
Correct |
7 ms |
11988 KB |
Output is correct |
22 |
Correct |
7 ms |
12116 KB |
Output is correct |
23 |
Correct |
7 ms |
12072 KB |
Output is correct |
24 |
Correct |
7 ms |
12116 KB |
Output is correct |
25 |
Correct |
7 ms |
12116 KB |
Output is correct |
26 |
Correct |
7 ms |
12044 KB |
Output is correct |
27 |
Correct |
8 ms |
12076 KB |
Output is correct |
28 |
Correct |
7 ms |
12080 KB |
Output is correct |
29 |
Correct |
7 ms |
12080 KB |
Output is correct |
30 |
Correct |
6 ms |
11988 KB |
Output is correct |
31 |
Correct |
8 ms |
12116 KB |
Output is correct |
32 |
Correct |
7 ms |
12016 KB |
Output is correct |
33 |
Correct |
6 ms |
11988 KB |
Output is correct |
34 |
Correct |
6 ms |
11988 KB |
Output is correct |
35 |
Correct |
6 ms |
12068 KB |
Output is correct |
36 |
Correct |
6 ms |
11988 KB |
Output is correct |
37 |
Correct |
8 ms |
12076 KB |
Output is correct |
38 |
Correct |
8 ms |
12120 KB |
Output is correct |
39 |
Correct |
7 ms |
11988 KB |
Output is correct |
40 |
Correct |
7 ms |
11980 KB |
Output is correct |
41 |
Correct |
7 ms |
11988 KB |
Output is correct |
42 |
Correct |
7 ms |
12012 KB |
Output is correct |
43 |
Correct |
6 ms |
12068 KB |
Output is correct |
44 |
Correct |
6 ms |
11988 KB |
Output is correct |
45 |
Correct |
6 ms |
11988 KB |
Output is correct |
46 |
Correct |
7 ms |
11988 KB |
Output is correct |
47 |
Correct |
6 ms |
11988 KB |
Output is correct |
48 |
Correct |
7 ms |
12072 KB |
Output is correct |
49 |
Correct |
7 ms |
12116 KB |
Output is correct |
50 |
Correct |
8 ms |
11988 KB |
Output is correct |
51 |
Correct |
7 ms |
11988 KB |
Output is correct |
52 |
Correct |
8 ms |
12072 KB |
Output is correct |
53 |
Correct |
7 ms |
12116 KB |
Output is correct |
54 |
Correct |
7 ms |
11976 KB |
Output is correct |
55 |
Correct |
7 ms |
11988 KB |
Output is correct |
56 |
Correct |
6 ms |
11988 KB |
Output is correct |
57 |
Correct |
6 ms |
12068 KB |
Output is correct |
58 |
Correct |
7 ms |
12116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
7 ms |
12068 KB |
Output is correct |
3 |
Correct |
6 ms |
12068 KB |
Output is correct |
4 |
Correct |
6 ms |
12064 KB |
Output is correct |
5 |
Correct |
6 ms |
11988 KB |
Output is correct |
6 |
Correct |
6 ms |
11988 KB |
Output is correct |
7 |
Correct |
6 ms |
11988 KB |
Output is correct |
8 |
Correct |
6 ms |
12068 KB |
Output is correct |
9 |
Correct |
6 ms |
11988 KB |
Output is correct |
10 |
Correct |
7 ms |
12044 KB |
Output is correct |
11 |
Correct |
6 ms |
12064 KB |
Output is correct |
12 |
Correct |
6 ms |
11988 KB |
Output is correct |
13 |
Correct |
6 ms |
11988 KB |
Output is correct |
14 |
Correct |
6 ms |
11988 KB |
Output is correct |
15 |
Correct |
6 ms |
11988 KB |
Output is correct |
16 |
Correct |
7 ms |
12132 KB |
Output is correct |
17 |
Correct |
8 ms |
12064 KB |
Output is correct |
18 |
Correct |
6 ms |
12068 KB |
Output is correct |
19 |
Correct |
6 ms |
11988 KB |
Output is correct |
20 |
Correct |
6 ms |
11988 KB |
Output is correct |
21 |
Correct |
7 ms |
11988 KB |
Output is correct |
22 |
Correct |
7 ms |
12116 KB |
Output is correct |
23 |
Correct |
7 ms |
12072 KB |
Output is correct |
24 |
Correct |
7 ms |
12116 KB |
Output is correct |
25 |
Correct |
7 ms |
12116 KB |
Output is correct |
26 |
Correct |
7 ms |
12044 KB |
Output is correct |
27 |
Correct |
8 ms |
12076 KB |
Output is correct |
28 |
Correct |
7 ms |
12080 KB |
Output is correct |
29 |
Correct |
7 ms |
12080 KB |
Output is correct |
30 |
Correct |
6 ms |
11988 KB |
Output is correct |
31 |
Correct |
8 ms |
12116 KB |
Output is correct |
32 |
Correct |
7 ms |
12016 KB |
Output is correct |
33 |
Correct |
6 ms |
11988 KB |
Output is correct |
34 |
Correct |
6 ms |
11988 KB |
Output is correct |
35 |
Correct |
6 ms |
12068 KB |
Output is correct |
36 |
Correct |
6 ms |
11988 KB |
Output is correct |
37 |
Correct |
8 ms |
12076 KB |
Output is correct |
38 |
Correct |
8 ms |
12120 KB |
Output is correct |
39 |
Correct |
7 ms |
11988 KB |
Output is correct |
40 |
Correct |
7 ms |
11980 KB |
Output is correct |
41 |
Correct |
7 ms |
11988 KB |
Output is correct |
42 |
Correct |
7 ms |
12012 KB |
Output is correct |
43 |
Correct |
6 ms |
12068 KB |
Output is correct |
44 |
Correct |
6 ms |
11988 KB |
Output is correct |
45 |
Correct |
6 ms |
11988 KB |
Output is correct |
46 |
Correct |
7 ms |
11988 KB |
Output is correct |
47 |
Correct |
6 ms |
11988 KB |
Output is correct |
48 |
Correct |
7 ms |
12072 KB |
Output is correct |
49 |
Correct |
7 ms |
12116 KB |
Output is correct |
50 |
Correct |
8 ms |
11988 KB |
Output is correct |
51 |
Correct |
7 ms |
11988 KB |
Output is correct |
52 |
Correct |
8 ms |
12072 KB |
Output is correct |
53 |
Correct |
7 ms |
12116 KB |
Output is correct |
54 |
Correct |
7 ms |
11976 KB |
Output is correct |
55 |
Correct |
7 ms |
11988 KB |
Output is correct |
56 |
Correct |
6 ms |
11988 KB |
Output is correct |
57 |
Correct |
6 ms |
12068 KB |
Output is correct |
58 |
Correct |
7 ms |
12116 KB |
Output is correct |
59 |
Correct |
280 ms |
36424 KB |
Output is correct |
60 |
Correct |
332 ms |
39248 KB |
Output is correct |
61 |
Correct |
7 ms |
11988 KB |
Output is correct |
62 |
Correct |
7 ms |
11988 KB |
Output is correct |
63 |
Correct |
239 ms |
34004 KB |
Output is correct |
64 |
Correct |
8 ms |
12500 KB |
Output is correct |
65 |
Correct |
14 ms |
13968 KB |
Output is correct |
66 |
Correct |
112 ms |
28088 KB |
Output is correct |
67 |
Correct |
416 ms |
47660 KB |
Output is correct |
68 |
Correct |
411 ms |
48164 KB |
Output is correct |
69 |
Correct |
12 ms |
12884 KB |
Output is correct |
70 |
Correct |
70 ms |
21412 KB |
Output is correct |
71 |
Correct |
255 ms |
42328 KB |
Output is correct |
72 |
Correct |
278 ms |
41144 KB |
Output is correct |
73 |
Correct |
80 ms |
19244 KB |
Output is correct |
74 |
Correct |
343 ms |
38108 KB |
Output is correct |
75 |
Correct |
24 ms |
15296 KB |
Output is correct |
76 |
Correct |
255 ms |
42080 KB |
Output is correct |
77 |
Correct |
273 ms |
42160 KB |
Output is correct |
78 |
Correct |
27 ms |
15564 KB |
Output is correct |
79 |
Correct |
404 ms |
45540 KB |
Output is correct |
80 |
Correct |
7 ms |
12244 KB |
Output is correct |
81 |
Correct |
84 ms |
21404 KB |
Output is correct |
82 |
Correct |
321 ms |
40000 KB |
Output is correct |
83 |
Correct |
387 ms |
38148 KB |
Output is correct |
84 |
Correct |
351 ms |
38112 KB |
Output is correct |
85 |
Correct |
360 ms |
38084 KB |
Output is correct |
86 |
Correct |
345 ms |
39260 KB |
Output is correct |
87 |
Correct |
365 ms |
39272 KB |
Output is correct |