답안 #550586

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
550586 2022-04-18T15:26:52 Z OttoTheDino Network (BOI15_net) C++17
100 / 100
428 ms 47704 KB
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,s,e)                  for (int i = s; i <= e; ++i)
#define rrep(i,s,e)                 for (int i = s; i >= e; --i)
#define pb                          push_back
#define pf                          push_front
#define fi                          first
#define se                          second
#define all(a)                      a.begin(), a.end()
#define SZ(a)                       (int)a.size()
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
 
const int mx = 5e5;
vi adj[mx+1], leaves;
int x;
 
void dfs (int u, int p) {
    if (SZ(adj[u])==1) leaves.pb(u);
    else x = u;
    for (int v : adj[u]) {
        if (v==p) continue;
        dfs (v,u);
    }
}
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
 
    int n; cin >> n;
    rep (i,1,n-1) {
        int u, v; cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
 
    dfs (1,-1);
 
    int m = leaves.size();
 
    cout << (m+1)/2 << "\n";
 
    rep (i,0,m/2-1) {
        cout << leaves[i] << " " << leaves[i+m/2] << "\n";
    }
 
    if (m%2) cout << leaves[m-1] << " " << leaves[m/2] << "\n";
 
    return 0;
}
 
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 11988 KB Output is correct
2 Correct 6 ms 11988 KB Output is correct
3 Correct 6 ms 11988 KB Output is correct
4 Correct 6 ms 12060 KB Output is correct
5 Correct 6 ms 11988 KB Output is correct
6 Correct 6 ms 12064 KB Output is correct
7 Correct 6 ms 11988 KB Output is correct
8 Correct 6 ms 11988 KB Output is correct
9 Correct 6 ms 11996 KB Output is correct
10 Correct 7 ms 11988 KB Output is correct
11 Correct 7 ms 12064 KB Output is correct
12 Correct 7 ms 12064 KB Output is correct
13 Correct 7 ms 12060 KB Output is correct
14 Correct 7 ms 11988 KB Output is correct
15 Correct 7 ms 12064 KB Output is correct
16 Correct 7 ms 11972 KB Output is correct
17 Correct 6 ms 11988 KB Output is correct
18 Correct 7 ms 12064 KB Output is correct
19 Correct 7 ms 11988 KB Output is correct
20 Correct 7 ms 11988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 11988 KB Output is correct
2 Correct 6 ms 11988 KB Output is correct
3 Correct 6 ms 11988 KB Output is correct
4 Correct 6 ms 12060 KB Output is correct
5 Correct 6 ms 11988 KB Output is correct
6 Correct 6 ms 12064 KB Output is correct
7 Correct 6 ms 11988 KB Output is correct
8 Correct 6 ms 11988 KB Output is correct
9 Correct 6 ms 11996 KB Output is correct
10 Correct 7 ms 11988 KB Output is correct
11 Correct 7 ms 12064 KB Output is correct
12 Correct 7 ms 12064 KB Output is correct
13 Correct 7 ms 12060 KB Output is correct
14 Correct 7 ms 11988 KB Output is correct
15 Correct 7 ms 12064 KB Output is correct
16 Correct 7 ms 11972 KB Output is correct
17 Correct 6 ms 11988 KB Output is correct
18 Correct 7 ms 12064 KB Output is correct
19 Correct 7 ms 11988 KB Output is correct
20 Correct 7 ms 11988 KB Output is correct
21 Correct 8 ms 11988 KB Output is correct
22 Correct 8 ms 12076 KB Output is correct
23 Correct 8 ms 12140 KB Output is correct
24 Correct 8 ms 12116 KB Output is correct
25 Correct 9 ms 12116 KB Output is correct
26 Correct 7 ms 12072 KB Output is correct
27 Correct 8 ms 12076 KB Output is correct
28 Correct 8 ms 12116 KB Output is correct
29 Correct 7 ms 12116 KB Output is correct
30 Correct 7 ms 11988 KB Output is correct
31 Correct 9 ms 12116 KB Output is correct
32 Correct 6 ms 12016 KB Output is correct
33 Correct 7 ms 11988 KB Output is correct
34 Correct 7 ms 12068 KB Output is correct
35 Correct 6 ms 11988 KB Output is correct
36 Correct 7 ms 11988 KB Output is correct
37 Correct 7 ms 12068 KB Output is correct
38 Correct 7 ms 12116 KB Output is correct
39 Correct 6 ms 12068 KB Output is correct
40 Correct 7 ms 11988 KB Output is correct
41 Correct 8 ms 12064 KB Output is correct
42 Correct 6 ms 11988 KB Output is correct
43 Correct 7 ms 12116 KB Output is correct
44 Correct 6 ms 11988 KB Output is correct
45 Correct 9 ms 11988 KB Output is correct
46 Correct 7 ms 11988 KB Output is correct
47 Correct 7 ms 12064 KB Output is correct
48 Correct 9 ms 11988 KB Output is correct
49 Correct 9 ms 12084 KB Output is correct
50 Correct 6 ms 12056 KB Output is correct
51 Correct 6 ms 11988 KB Output is correct
52 Correct 6 ms 11988 KB Output is correct
53 Correct 8 ms 12116 KB Output is correct
54 Correct 7 ms 12068 KB Output is correct
55 Correct 7 ms 11988 KB Output is correct
56 Correct 7 ms 12060 KB Output is correct
57 Correct 7 ms 11988 KB Output is correct
58 Correct 7 ms 12080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 11988 KB Output is correct
2 Correct 6 ms 11988 KB Output is correct
3 Correct 6 ms 11988 KB Output is correct
4 Correct 6 ms 12060 KB Output is correct
5 Correct 6 ms 11988 KB Output is correct
6 Correct 6 ms 12064 KB Output is correct
7 Correct 6 ms 11988 KB Output is correct
8 Correct 6 ms 11988 KB Output is correct
9 Correct 6 ms 11996 KB Output is correct
10 Correct 7 ms 11988 KB Output is correct
11 Correct 7 ms 12064 KB Output is correct
12 Correct 7 ms 12064 KB Output is correct
13 Correct 7 ms 12060 KB Output is correct
14 Correct 7 ms 11988 KB Output is correct
15 Correct 7 ms 12064 KB Output is correct
16 Correct 7 ms 11972 KB Output is correct
17 Correct 6 ms 11988 KB Output is correct
18 Correct 7 ms 12064 KB Output is correct
19 Correct 7 ms 11988 KB Output is correct
20 Correct 7 ms 11988 KB Output is correct
21 Correct 8 ms 11988 KB Output is correct
22 Correct 8 ms 12076 KB Output is correct
23 Correct 8 ms 12140 KB Output is correct
24 Correct 8 ms 12116 KB Output is correct
25 Correct 9 ms 12116 KB Output is correct
26 Correct 7 ms 12072 KB Output is correct
27 Correct 8 ms 12076 KB Output is correct
28 Correct 8 ms 12116 KB Output is correct
29 Correct 7 ms 12116 KB Output is correct
30 Correct 7 ms 11988 KB Output is correct
31 Correct 9 ms 12116 KB Output is correct
32 Correct 6 ms 12016 KB Output is correct
33 Correct 7 ms 11988 KB Output is correct
34 Correct 7 ms 12068 KB Output is correct
35 Correct 6 ms 11988 KB Output is correct
36 Correct 7 ms 11988 KB Output is correct
37 Correct 7 ms 12068 KB Output is correct
38 Correct 7 ms 12116 KB Output is correct
39 Correct 6 ms 12068 KB Output is correct
40 Correct 7 ms 11988 KB Output is correct
41 Correct 8 ms 12064 KB Output is correct
42 Correct 6 ms 11988 KB Output is correct
43 Correct 7 ms 12116 KB Output is correct
44 Correct 6 ms 11988 KB Output is correct
45 Correct 9 ms 11988 KB Output is correct
46 Correct 7 ms 11988 KB Output is correct
47 Correct 7 ms 12064 KB Output is correct
48 Correct 9 ms 11988 KB Output is correct
49 Correct 9 ms 12084 KB Output is correct
50 Correct 6 ms 12056 KB Output is correct
51 Correct 6 ms 11988 KB Output is correct
52 Correct 6 ms 11988 KB Output is correct
53 Correct 8 ms 12116 KB Output is correct
54 Correct 7 ms 12068 KB Output is correct
55 Correct 7 ms 11988 KB Output is correct
56 Correct 7 ms 12060 KB Output is correct
57 Correct 7 ms 11988 KB Output is correct
58 Correct 7 ms 12080 KB Output is correct
59 Correct 303 ms 35960 KB Output is correct
60 Correct 393 ms 38860 KB Output is correct
61 Correct 6 ms 11988 KB Output is correct
62 Correct 7 ms 11940 KB Output is correct
63 Correct 302 ms 33668 KB Output is correct
64 Correct 9 ms 12372 KB Output is correct
65 Correct 15 ms 13884 KB Output is correct
66 Correct 139 ms 27888 KB Output is correct
67 Correct 406 ms 46796 KB Output is correct
68 Correct 425 ms 47704 KB Output is correct
69 Correct 11 ms 12884 KB Output is correct
70 Correct 73 ms 21216 KB Output is correct
71 Correct 261 ms 41896 KB Output is correct
72 Correct 296 ms 40652 KB Output is correct
73 Correct 96 ms 19020 KB Output is correct
74 Correct 373 ms 37648 KB Output is correct
75 Correct 26 ms 15180 KB Output is correct
76 Correct 284 ms 41492 KB Output is correct
77 Correct 278 ms 41636 KB Output is correct
78 Correct 30 ms 15308 KB Output is correct
79 Correct 428 ms 45288 KB Output is correct
80 Correct 8 ms 12204 KB Output is correct
81 Correct 86 ms 21260 KB Output is correct
82 Correct 373 ms 39624 KB Output is correct
83 Correct 392 ms 37664 KB Output is correct
84 Correct 347 ms 37696 KB Output is correct
85 Correct 379 ms 37656 KB Output is correct
86 Correct 395 ms 38700 KB Output is correct
87 Correct 355 ms 38792 KB Output is correct