# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
715752 | 2023-03-27T18:50:18 Z | n1k | 슈퍼트리 잇기 (IOI20_supertrees) | C++17 | 278 ms | 26112 KB |
#include "supertrees.h" #include <vector> #include <bits/stdc++.h> using namespace std; #define sz(a) (a).size() vector<vector<int>> components; vector<bool> vis; std::vector<std::vector<int>> adj; int n; bool dfs(int u){ vis[u] = 1; // u connectet to all in component for(auto v : components[sz(components) - 1]){ if(!adj[v][u]){ return false; } } components[sz(components) - 1].push_back(u); for(int v = 0; v < n; v++){ if(vis[v]){ continue; } if(adj[u][v]){ if(!dfs(v)){ return false; } } } return true; } int construct(std::vector<std::vector<int>> p) { adj = p; n = p.size(); vis.resize(n); for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ if(p[i][j] == 3){ return 0; } } } // p[i][j] = 1 -> same component // p[j][k] = 1 -> p[i][k] = 1 // add j // j -> has connection to all in component // dfs -> j for(int u = 0; u < n; u++){ if(vis[u]){ continue; } components.push_back(vector<int>()); if(!dfs(u)){ return 0; } } vis.assign(n, 0); // construckt trees vector<vector<int>> mat(n, vector<int>(n)); for(auto comp : components){ vector<int> roots; for(auto u : comp){ if(vis[u]){ continue; } roots.push_back(u); for(int i = 0; i < n; i++){ if(u == i){ continue; } if(p[u][i] == 1){ vis[i] = 1; mat[u][i] = mat[i][u] = 1; } } } if(sz(roots) == 2){ return 0; }else if(sz(roots) > 2){ for(int i = 0; i < sz(roots); i++){ mat[roots[i]][roots[(i + 1) % sz(roots)]] = mat[roots[(i + 1) % sz(roots)]][roots[i]] = 1; } } } build(mat); return 1; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 14 ms | 1364 KB | Output is correct |
7 | Correct | 278 ms | 26028 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 14 ms | 1364 KB | Output is correct |
7 | Correct | 278 ms | 26028 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 9 ms | 1364 KB | Output is correct |
13 | Correct | 200 ms | 25984 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 5 ms | 716 KB | Output is correct |
17 | Correct | 89 ms | 12036 KB | Output is correct |
18 | Correct | 1 ms | 212 KB | Output is correct |
19 | Correct | 1 ms | 212 KB | Output is correct |
20 | Correct | 69 ms | 6776 KB | Output is correct |
21 | Correct | 181 ms | 26112 KB | Output is correct |
22 | Correct | 183 ms | 26060 KB | Output is correct |
23 | Correct | 191 ms | 25916 KB | Output is correct |
24 | Correct | 193 ms | 26024 KB | Output is correct |
25 | Correct | 73 ms | 12048 KB | Output is correct |
26 | Correct | 71 ms | 12036 KB | Output is correct |
27 | Correct | 217 ms | 26016 KB | Output is correct |
28 | Correct | 177 ms | 26044 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 8 ms | 1364 KB | Output is correct |
9 | Correct | 181 ms | 26060 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 8 ms | 1364 KB | Output is correct |
13 | Correct | 217 ms | 25988 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 212 KB | Output is correct |
16 | Correct | 5 ms | 716 KB | Output is correct |
17 | Correct | 81 ms | 12040 KB | Output is correct |
18 | Correct | 0 ms | 212 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 0 ms | 212 KB | Output is correct |
21 | Correct | 56 ms | 6732 KB | Output is correct |
22 | Correct | 179 ms | 25996 KB | Output is correct |
23 | Correct | 194 ms | 25988 KB | Output is correct |
24 | Correct | 192 ms | 25996 KB | Output is correct |
25 | Correct | 109 ms | 16076 KB | Output is correct |
26 | Correct | 79 ms | 12048 KB | Output is correct |
27 | Correct | 176 ms | 25992 KB | Output is correct |
28 | Correct | 238 ms | 26032 KB | Output is correct |
29 | Correct | 74 ms | 16136 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 50 ms | 6664 KB | Output is correct |
5 | Correct | 183 ms | 25948 KB | Output is correct |
6 | Correct | 181 ms | 25976 KB | Output is correct |
7 | Correct | 192 ms | 26060 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 49 ms | 6708 KB | Output is correct |
10 | Correct | 186 ms | 26000 KB | Output is correct |
11 | Correct | 196 ms | 26032 KB | Output is correct |
12 | Correct | 206 ms | 25972 KB | Output is correct |
13 | Correct | 1 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 53 ms | 6664 KB | Output is correct |
17 | Correct | 179 ms | 25996 KB | Output is correct |
18 | Correct | 203 ms | 25988 KB | Output is correct |
19 | Correct | 186 ms | 26096 KB | Output is correct |
20 | Correct | 206 ms | 25984 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 14 ms | 1364 KB | Output is correct |
7 | Correct | 278 ms | 26028 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 9 ms | 1364 KB | Output is correct |
13 | Correct | 200 ms | 25984 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 5 ms | 716 KB | Output is correct |
17 | Correct | 89 ms | 12036 KB | Output is correct |
18 | Correct | 1 ms | 212 KB | Output is correct |
19 | Correct | 1 ms | 212 KB | Output is correct |
20 | Correct | 69 ms | 6776 KB | Output is correct |
21 | Correct | 181 ms | 26112 KB | Output is correct |
22 | Correct | 183 ms | 26060 KB | Output is correct |
23 | Correct | 191 ms | 25916 KB | Output is correct |
24 | Correct | 193 ms | 26024 KB | Output is correct |
25 | Correct | 73 ms | 12048 KB | Output is correct |
26 | Correct | 71 ms | 12036 KB | Output is correct |
27 | Correct | 217 ms | 26016 KB | Output is correct |
28 | Correct | 177 ms | 26044 KB | Output is correct |
29 | Correct | 0 ms | 212 KB | Output is correct |
30 | Correct | 0 ms | 212 KB | Output is correct |
31 | Correct | 1 ms | 212 KB | Output is correct |
32 | Correct | 0 ms | 212 KB | Output is correct |
33 | Correct | 0 ms | 212 KB | Output is correct |
34 | Correct | 0 ms | 212 KB | Output is correct |
35 | Correct | 0 ms | 212 KB | Output is correct |
36 | Correct | 8 ms | 1364 KB | Output is correct |
37 | Correct | 181 ms | 26060 KB | Output is correct |
38 | Correct | 0 ms | 212 KB | Output is correct |
39 | Correct | 0 ms | 212 KB | Output is correct |
40 | Correct | 8 ms | 1364 KB | Output is correct |
41 | Correct | 217 ms | 25988 KB | Output is correct |
42 | Correct | 1 ms | 212 KB | Output is correct |
43 | Correct | 0 ms | 212 KB | Output is correct |
44 | Correct | 5 ms | 716 KB | Output is correct |
45 | Correct | 81 ms | 12040 KB | Output is correct |
46 | Correct | 0 ms | 212 KB | Output is correct |
47 | Correct | 0 ms | 212 KB | Output is correct |
48 | Correct | 0 ms | 212 KB | Output is correct |
49 | Correct | 56 ms | 6732 KB | Output is correct |
50 | Correct | 179 ms | 25996 KB | Output is correct |
51 | Correct | 194 ms | 25988 KB | Output is correct |
52 | Correct | 192 ms | 25996 KB | Output is correct |
53 | Correct | 109 ms | 16076 KB | Output is correct |
54 | Correct | 79 ms | 12048 KB | Output is correct |
55 | Correct | 176 ms | 25992 KB | Output is correct |
56 | Correct | 238 ms | 26032 KB | Output is correct |
57 | Correct | 74 ms | 16136 KB | Output is correct |
58 | Correct | 0 ms | 212 KB | Output is correct |
59 | Correct | 0 ms | 212 KB | Output is correct |
60 | Correct | 5 ms | 724 KB | Output is correct |
61 | Correct | 90 ms | 12032 KB | Output is correct |
62 | Correct | 1 ms | 212 KB | Output is correct |
63 | Correct | 0 ms | 212 KB | Output is correct |
64 | Correct | 1 ms | 212 KB | Output is correct |
65 | Correct | 47 ms | 6768 KB | Output is correct |
66 | Correct | 75 ms | 12036 KB | Output is correct |
67 | Correct | 73 ms | 12048 KB | Output is correct |
68 | Correct | 72 ms | 12048 KB | Output is correct |
69 | Correct | 76 ms | 16076 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 14 ms | 1364 KB | Output is correct |
7 | Correct | 278 ms | 26028 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 9 ms | 1364 KB | Output is correct |
13 | Correct | 200 ms | 25984 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 1 ms | 212 KB | Output is correct |
16 | Correct | 5 ms | 716 KB | Output is correct |
17 | Correct | 89 ms | 12036 KB | Output is correct |
18 | Correct | 1 ms | 212 KB | Output is correct |
19 | Correct | 1 ms | 212 KB | Output is correct |
20 | Correct | 69 ms | 6776 KB | Output is correct |
21 | Correct | 181 ms | 26112 KB | Output is correct |
22 | Correct | 183 ms | 26060 KB | Output is correct |
23 | Correct | 191 ms | 25916 KB | Output is correct |
24 | Correct | 193 ms | 26024 KB | Output is correct |
25 | Correct | 73 ms | 12048 KB | Output is correct |
26 | Correct | 71 ms | 12036 KB | Output is correct |
27 | Correct | 217 ms | 26016 KB | Output is correct |
28 | Correct | 177 ms | 26044 KB | Output is correct |
29 | Correct | 0 ms | 212 KB | Output is correct |
30 | Correct | 0 ms | 212 KB | Output is correct |
31 | Correct | 1 ms | 212 KB | Output is correct |
32 | Correct | 0 ms | 212 KB | Output is correct |
33 | Correct | 0 ms | 212 KB | Output is correct |
34 | Correct | 0 ms | 212 KB | Output is correct |
35 | Correct | 0 ms | 212 KB | Output is correct |
36 | Correct | 8 ms | 1364 KB | Output is correct |
37 | Correct | 181 ms | 26060 KB | Output is correct |
38 | Correct | 0 ms | 212 KB | Output is correct |
39 | Correct | 0 ms | 212 KB | Output is correct |
40 | Correct | 8 ms | 1364 KB | Output is correct |
41 | Correct | 217 ms | 25988 KB | Output is correct |
42 | Correct | 1 ms | 212 KB | Output is correct |
43 | Correct | 0 ms | 212 KB | Output is correct |
44 | Correct | 5 ms | 716 KB | Output is correct |
45 | Correct | 81 ms | 12040 KB | Output is correct |
46 | Correct | 0 ms | 212 KB | Output is correct |
47 | Correct | 0 ms | 212 KB | Output is correct |
48 | Correct | 0 ms | 212 KB | Output is correct |
49 | Correct | 56 ms | 6732 KB | Output is correct |
50 | Correct | 179 ms | 25996 KB | Output is correct |
51 | Correct | 194 ms | 25988 KB | Output is correct |
52 | Correct | 192 ms | 25996 KB | Output is correct |
53 | Correct | 109 ms | 16076 KB | Output is correct |
54 | Correct | 79 ms | 12048 KB | Output is correct |
55 | Correct | 176 ms | 25992 KB | Output is correct |
56 | Correct | 238 ms | 26032 KB | Output is correct |
57 | Correct | 74 ms | 16136 KB | Output is correct |
58 | Correct | 1 ms | 212 KB | Output is correct |
59 | Correct | 0 ms | 212 KB | Output is correct |
60 | Correct | 0 ms | 212 KB | Output is correct |
61 | Correct | 50 ms | 6664 KB | Output is correct |
62 | Correct | 183 ms | 25948 KB | Output is correct |
63 | Correct | 181 ms | 25976 KB | Output is correct |
64 | Correct | 192 ms | 26060 KB | Output is correct |
65 | Correct | 0 ms | 212 KB | Output is correct |
66 | Correct | 49 ms | 6708 KB | Output is correct |
67 | Correct | 186 ms | 26000 KB | Output is correct |
68 | Correct | 196 ms | 26032 KB | Output is correct |
69 | Correct | 206 ms | 25972 KB | Output is correct |
70 | Correct | 1 ms | 212 KB | Output is correct |
71 | Correct | 1 ms | 212 KB | Output is correct |
72 | Correct | 1 ms | 212 KB | Output is correct |
73 | Correct | 53 ms | 6664 KB | Output is correct |
74 | Correct | 179 ms | 25996 KB | Output is correct |
75 | Correct | 203 ms | 25988 KB | Output is correct |
76 | Correct | 186 ms | 26096 KB | Output is correct |
77 | Correct | 206 ms | 25984 KB | Output is correct |
78 | Correct | 0 ms | 212 KB | Output is correct |
79 | Correct | 0 ms | 212 KB | Output is correct |
80 | Correct | 5 ms | 724 KB | Output is correct |
81 | Correct | 90 ms | 12032 KB | Output is correct |
82 | Correct | 1 ms | 212 KB | Output is correct |
83 | Correct | 0 ms | 212 KB | Output is correct |
84 | Correct | 1 ms | 212 KB | Output is correct |
85 | Correct | 47 ms | 6768 KB | Output is correct |
86 | Correct | 75 ms | 12036 KB | Output is correct |
87 | Correct | 73 ms | 12048 KB | Output is correct |
88 | Correct | 72 ms | 12048 KB | Output is correct |
89 | Correct | 76 ms | 16076 KB | Output is correct |
90 | Correct | 1 ms | 212 KB | Output is correct |
91 | Correct | 0 ms | 212 KB | Output is correct |
92 | Correct | 4 ms | 724 KB | Output is correct |
93 | Correct | 83 ms | 12040 KB | Output is correct |
94 | Correct | 0 ms | 212 KB | Output is correct |
95 | Correct | 1 ms | 212 KB | Output is correct |
96 | Correct | 1 ms | 212 KB | Output is correct |
97 | Correct | 20 ms | 3708 KB | Output is correct |
98 | Correct | 80 ms | 14080 KB | Output is correct |
99 | Correct | 72 ms | 14068 KB | Output is correct |
100 | Correct | 72 ms | 14072 KB | Output is correct |
101 | Correct | 77 ms | 14072 KB | Output is correct |
102 | Correct | 80 ms | 14080 KB | Output is correct |
103 | Correct | 79 ms | 14072 KB | Output is correct |
104 | Correct | 84 ms | 14068 KB | Output is correct |
105 | Correct | 83 ms | 14028 KB | Output is correct |