# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
22983 | 2017-05-01T02:34:20 Z | model_code | Network (BOI15_net) | C++11 | 873 ms | 63228 KB |
/*/ Task: net Model solution Author: Bartosz Kostka /*/ #include "bits/stdc++.h" using namespace std; const int MAXN = 500007; bool odw[MAXN]; int leaves[MAXN]; int numleaves; vector <int> G[MAXN], S[MAXN]; void dfs(int v) { odw[v] = true; if((int)G[v].size() == 1) leaves[v] = 1; for(auto w : G[v]) if(odw[w]==false) { dfs(w); leaves[v] += leaves[w]; } } int findcut(int v) { odw[v] = true; for(auto w : G[v]) if(odw[w] == false) if(leaves[w] > numleaves/2) return findcut(w); return v; } void newdfs(int v, int tree) { //cerr << v << " " << tree << "T\n"; odw[v] = true; if((int)G[v].size() == 1) S[tree].push_back(v); for(auto w : G[v]) if(odw[w] == false) newdfs(w,tree); } int subtree; int cut(int n) { dfs(1); for(int i=1; i<=n; i++) odw[i] = false; int w = findcut(1); for(int i=1; i<=n; i++) odw[i] = false; odw[w] = true; for(auto v : G[w]) newdfs(v,++subtree); return w; } vector <int> W; int next(int e, int nn) { e += 2; if(e==nn) e = 1; return e; } int main() { int n; scanf("%d", &n); if(n==1) { printf("0\n"); return 0; } if(n==2) { printf("1\n1 2\n"); return 0; } for(int i=1; i<n; i++) { int a, b; scanf("%d%d", &a, &b); G[a].push_back(b); G[b].push_back(a); } for(int i=1; i<=n; i++) if((int)G[i].size() == 1) numleaves++; int res = (numleaves+1)/2; printf("%d\n", res); int w = cut(n); W.resize(2*res); int e = 0; for(int i=1; i<=subtree; i++) { for(auto ele : S[i]) { W[e] = ele; e = next(e,2*res); //cerr << ele << "." << e << "\n"; } } if((!W.empty()) and W.back() == 0) W.back() = w; for(int i=0; i<(int)W.size(); i+=2) printf("%d %d\n", W[i], W[i+1]); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 27904 KB | Output is correct |
2 | Correct | 3 ms | 27904 KB | Output is correct |
3 | Correct | 9 ms | 27904 KB | Output is correct |
4 | Correct | 6 ms | 27904 KB | Output is correct |
5 | Correct | 3 ms | 27904 KB | Output is correct |
6 | Correct | 9 ms | 27904 KB | Output is correct |
7 | Correct | 6 ms | 27904 KB | Output is correct |
8 | Correct | 3 ms | 27904 KB | Output is correct |
9 | Correct | 3 ms | 27904 KB | Output is correct |
10 | Correct | 3 ms | 27904 KB | Output is correct |
11 | Correct | 6 ms | 27904 KB | Output is correct |
12 | Correct | 6 ms | 27904 KB | Output is correct |
13 | Correct | 9 ms | 27904 KB | Output is correct |
14 | Correct | 13 ms | 27904 KB | Output is correct |
15 | Correct | 9 ms | 27904 KB | Output is correct |
16 | Correct | 3 ms | 27904 KB | Output is correct |
17 | Correct | 3 ms | 27904 KB | Output is correct |
18 | Correct | 6 ms | 27904 KB | Output is correct |
19 | Correct | 3 ms | 27904 KB | Output is correct |
20 | Correct | 3 ms | 27904 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 27904 KB | Output is correct |
2 | Correct | 3 ms | 27904 KB | Output is correct |
3 | Correct | 9 ms | 27904 KB | Output is correct |
4 | Correct | 6 ms | 27904 KB | Output is correct |
5 | Correct | 3 ms | 27904 KB | Output is correct |
6 | Correct | 9 ms | 27904 KB | Output is correct |
7 | Correct | 6 ms | 27904 KB | Output is correct |
8 | Correct | 3 ms | 27904 KB | Output is correct |
9 | Correct | 3 ms | 27904 KB | Output is correct |
10 | Correct | 3 ms | 27904 KB | Output is correct |
11 | Correct | 6 ms | 27904 KB | Output is correct |
12 | Correct | 6 ms | 27904 KB | Output is correct |
13 | Correct | 9 ms | 27904 KB | Output is correct |
14 | Correct | 13 ms | 27904 KB | Output is correct |
15 | Correct | 9 ms | 27904 KB | Output is correct |
16 | Correct | 3 ms | 27904 KB | Output is correct |
17 | Correct | 3 ms | 27904 KB | Output is correct |
18 | Correct | 6 ms | 27904 KB | Output is correct |
19 | Correct | 3 ms | 27904 KB | Output is correct |
20 | Correct | 3 ms | 27904 KB | Output is correct |
21 | Correct | 0 ms | 27904 KB | Output is correct |
22 | Correct | 6 ms | 28036 KB | Output is correct |
23 | Correct | 3 ms | 28036 KB | Output is correct |
24 | Correct | 6 ms | 28036 KB | Output is correct |
25 | Correct | 13 ms | 28036 KB | Output is correct |
26 | Correct | 3 ms | 28036 KB | Output is correct |
27 | Correct | 9 ms | 28036 KB | Output is correct |
28 | Correct | 3 ms | 28036 KB | Output is correct |
29 | Correct | 13 ms | 28036 KB | Output is correct |
30 | Correct | 6 ms | 27904 KB | Output is correct |
31 | Correct | 3 ms | 28036 KB | Output is correct |
32 | Correct | 3 ms | 27904 KB | Output is correct |
33 | Correct | 3 ms | 27904 KB | Output is correct |
34 | Correct | 13 ms | 27904 KB | Output is correct |
35 | Correct | 3 ms | 27904 KB | Output is correct |
36 | Correct | 3 ms | 27904 KB | Output is correct |
37 | Correct | 3 ms | 27904 KB | Output is correct |
38 | Correct | 0 ms | 27904 KB | Output is correct |
39 | Correct | 6 ms | 27904 KB | Output is correct |
40 | Correct | 3 ms | 27904 KB | Output is correct |
41 | Correct | 9 ms | 27904 KB | Output is correct |
42 | Correct | 13 ms | 27904 KB | Output is correct |
43 | Correct | 6 ms | 28036 KB | Output is correct |
44 | Correct | 6 ms | 27904 KB | Output is correct |
45 | Correct | 3 ms | 27904 KB | Output is correct |
46 | Correct | 6 ms | 27904 KB | Output is correct |
47 | Correct | 6 ms | 27904 KB | Output is correct |
48 | Correct | 6 ms | 27904 KB | Output is correct |
49 | Correct | 6 ms | 28036 KB | Output is correct |
50 | Correct | 3 ms | 27904 KB | Output is correct |
51 | Correct | 6 ms | 27904 KB | Output is correct |
52 | Correct | 3 ms | 27904 KB | Output is correct |
53 | Correct | 9 ms | 27904 KB | Output is correct |
54 | Correct | 3 ms | 27904 KB | Output is correct |
55 | Correct | 6 ms | 27904 KB | Output is correct |
56 | Correct | 6 ms | 27904 KB | Output is correct |
57 | Correct | 6 ms | 27904 KB | Output is correct |
58 | Correct | 3 ms | 28036 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 27904 KB | Output is correct |
2 | Correct | 3 ms | 27904 KB | Output is correct |
3 | Correct | 9 ms | 27904 KB | Output is correct |
4 | Correct | 6 ms | 27904 KB | Output is correct |
5 | Correct | 3 ms | 27904 KB | Output is correct |
6 | Correct | 9 ms | 27904 KB | Output is correct |
7 | Correct | 6 ms | 27904 KB | Output is correct |
8 | Correct | 3 ms | 27904 KB | Output is correct |
9 | Correct | 3 ms | 27904 KB | Output is correct |
10 | Correct | 3 ms | 27904 KB | Output is correct |
11 | Correct | 6 ms | 27904 KB | Output is correct |
12 | Correct | 6 ms | 27904 KB | Output is correct |
13 | Correct | 9 ms | 27904 KB | Output is correct |
14 | Correct | 13 ms | 27904 KB | Output is correct |
15 | Correct | 9 ms | 27904 KB | Output is correct |
16 | Correct | 3 ms | 27904 KB | Output is correct |
17 | Correct | 3 ms | 27904 KB | Output is correct |
18 | Correct | 6 ms | 27904 KB | Output is correct |
19 | Correct | 3 ms | 27904 KB | Output is correct |
20 | Correct | 3 ms | 27904 KB | Output is correct |
21 | Correct | 0 ms | 27904 KB | Output is correct |
22 | Correct | 6 ms | 28036 KB | Output is correct |
23 | Correct | 3 ms | 28036 KB | Output is correct |
24 | Correct | 6 ms | 28036 KB | Output is correct |
25 | Correct | 13 ms | 28036 KB | Output is correct |
26 | Correct | 3 ms | 28036 KB | Output is correct |
27 | Correct | 9 ms | 28036 KB | Output is correct |
28 | Correct | 3 ms | 28036 KB | Output is correct |
29 | Correct | 13 ms | 28036 KB | Output is correct |
30 | Correct | 6 ms | 27904 KB | Output is correct |
31 | Correct | 3 ms | 28036 KB | Output is correct |
32 | Correct | 3 ms | 27904 KB | Output is correct |
33 | Correct | 3 ms | 27904 KB | Output is correct |
34 | Correct | 13 ms | 27904 KB | Output is correct |
35 | Correct | 3 ms | 27904 KB | Output is correct |
36 | Correct | 3 ms | 27904 KB | Output is correct |
37 | Correct | 3 ms | 27904 KB | Output is correct |
38 | Correct | 0 ms | 27904 KB | Output is correct |
39 | Correct | 6 ms | 27904 KB | Output is correct |
40 | Correct | 3 ms | 27904 KB | Output is correct |
41 | Correct | 9 ms | 27904 KB | Output is correct |
42 | Correct | 13 ms | 27904 KB | Output is correct |
43 | Correct | 6 ms | 28036 KB | Output is correct |
44 | Correct | 6 ms | 27904 KB | Output is correct |
45 | Correct | 3 ms | 27904 KB | Output is correct |
46 | Correct | 6 ms | 27904 KB | Output is correct |
47 | Correct | 6 ms | 27904 KB | Output is correct |
48 | Correct | 6 ms | 27904 KB | Output is correct |
49 | Correct | 6 ms | 28036 KB | Output is correct |
50 | Correct | 3 ms | 27904 KB | Output is correct |
51 | Correct | 6 ms | 27904 KB | Output is correct |
52 | Correct | 3 ms | 27904 KB | Output is correct |
53 | Correct | 9 ms | 27904 KB | Output is correct |
54 | Correct | 3 ms | 27904 KB | Output is correct |
55 | Correct | 6 ms | 27904 KB | Output is correct |
56 | Correct | 6 ms | 27904 KB | Output is correct |
57 | Correct | 6 ms | 27904 KB | Output is correct |
58 | Correct | 3 ms | 28036 KB | Output is correct |
59 | Correct | 549 ms | 48848 KB | Output is correct |
60 | Correct | 616 ms | 47496 KB | Output is correct |
61 | Correct | 3 ms | 27904 KB | Output is correct |
62 | Correct | 6 ms | 27904 KB | Output is correct |
63 | Correct | 483 ms | 45180 KB | Output is correct |
64 | Correct | 9 ms | 28144 KB | Output is correct |
65 | Correct | 26 ms | 29420 KB | Output is correct |
66 | Correct | 279 ms | 41416 KB | Output is correct |
67 | Correct | 749 ms | 55924 KB | Output is correct |
68 | Correct | 803 ms | 56716 KB | Output is correct |
69 | Correct | 16 ms | 29032 KB | Output is correct |
70 | Correct | 143 ms | 38884 KB | Output is correct |
71 | Correct | 483 ms | 63228 KB | Output is correct |
72 | Correct | 473 ms | 61308 KB | Output is correct |
73 | Correct | 129 ms | 33120 KB | Output is correct |
74 | Correct | 689 ms | 46588 KB | Output is correct |
75 | Correct | 39 ms | 31068 KB | Output is correct |
76 | Correct | 449 ms | 55988 KB | Output is correct |
77 | Correct | 483 ms | 56352 KB | Output is correct |
78 | Correct | 49 ms | 30528 KB | Output is correct |
79 | Correct | 873 ms | 54176 KB | Output is correct |
80 | Correct | 9 ms | 28168 KB | Output is correct |
81 | Correct | 143 ms | 37172 KB | Output is correct |
82 | Correct | 613 ms | 54644 KB | Output is correct |
83 | Correct | 719 ms | 46560 KB | Output is correct |
84 | Correct | 689 ms | 46956 KB | Output is correct |
85 | Correct | 709 ms | 47328 KB | Output is correct |
86 | Correct | 629 ms | 47848 KB | Output is correct |
87 | Correct | 703 ms | 47876 KB | Output is correct |