답안 #366038

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
366038 2021-02-12T19:49:04 Z mjhmjh1104 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
280 ms 24428 KB
#include "supertrees.h"
#include <vector>
using namespace std;

int uf[1006];

int _find(int x) {
    if (uf[x] == -1) return x;
    return uf[x] = _find(uf[x]);
}

void _merge(int x, int y) {
    x = _find(x), y = _find(y);
    if (x != y) uf[x] = y;
}

vector<int> v[1006], u[1006];
vector<vector<int>> adj;

int construct(vector<vector<int>> p) {
	int n = p.size();
	adj.resize(n);
	for (int i = 0; i < n; i++) adj[i].resize(n, 0);
	for (int i = 0; i < n; i++) uf[i] = -1;
	for (int i = 0; i < n; i++) for (int j = 0; j < i; j++) if (p[i][j]) _merge(i, j);
	for (int i = 0; i < n; i++) v[_find(i)].push_back(i);
	for (int t = 0; t < n; t++) for (int i = 0; i < (int)v[t].size(); i++) for (int j = 0; j < i; j++) if (p[v[t][i]][v[t][j]] == 0 || p[v[t][i]][v[t][j]] == 3) return 0;
	for (int t = 0; t < n; t++) if (!v[t].empty()) {
        for (int i = 0; i < n; i++) uf[i] = -1, u[i].clear();
        for (int i = 0; i < (int)v[t].size(); i++) for (int j = 0; j < i; j++) if (p[v[t][i]][v[t][j]] == 1) _merge(v[t][i], v[t][j]);
        for (int i = 0; i < (int)v[t].size(); i++) for (int j = 0; j < i; j++) if (_find(v[t][i]) == _find(v[t][j]) && p[v[t][i]][v[t][j]] == 2) return 0;
        for (int i = 0; i < (int)v[t].size(); i++) u[_find(v[t][i])].push_back(v[t][i]);
        vector<int> cycle;
        for (int i = 0; i < n; i++) if (!u[i].empty()) {
            cycle.push_back(u[i][0]);
            for (int j = 1; j < (int)u[i].size(); j++) adj[u[i][j - 1]][u[i][j]] = adj[u[i][j]][u[i][j - 1]] = 1;
        }
        for (int i = 1; i < (int)cycle.size(); i++) adj[cycle[i - 1]][cycle[i]] = adj[cycle[i]][cycle[i - 1]] = 1;
        if ((int)cycle.size() > 2) adj[cycle.back()][cycle[0]] = adj[cycle[0]][cycle.back()] = 1;
        else if ((int)cycle.size() == 2) return 0;
	}
	build(adj);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 11 ms 1388 KB Output is correct
7 Correct 260 ms 24108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 11 ms 1388 KB Output is correct
7 Correct 260 ms 24108 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 10 ms 1388 KB Output is correct
13 Correct 259 ms 24172 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 5 ms 876 KB Output is correct
17 Correct 120 ms 14188 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 0 ms 364 KB Output is correct
20 Correct 63 ms 6380 KB Output is correct
21 Correct 249 ms 24044 KB Output is correct
22 Correct 251 ms 24172 KB Output is correct
23 Correct 275 ms 24172 KB Output is correct
24 Correct 248 ms 24172 KB Output is correct
25 Correct 111 ms 14188 KB Output is correct
26 Correct 110 ms 14200 KB Output is correct
27 Correct 261 ms 24044 KB Output is correct
28 Correct 252 ms 24428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 12 ms 1388 KB Output is correct
9 Correct 248 ms 24172 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 11 ms 1388 KB Output is correct
13 Correct 252 ms 24184 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
16 Correct 5 ms 876 KB Output is correct
17 Correct 119 ms 14188 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 69 ms 6636 KB Output is correct
22 Correct 250 ms 24300 KB Output is correct
23 Correct 253 ms 24320 KB Output is correct
24 Correct 267 ms 24172 KB Output is correct
25 Correct 115 ms 14188 KB Output is correct
26 Correct 110 ms 14188 KB Output is correct
27 Correct 250 ms 24192 KB Output is correct
28 Correct 258 ms 24172 KB Output is correct
29 Correct 112 ms 14444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 63 ms 6380 KB Output is correct
5 Correct 255 ms 24300 KB Output is correct
6 Correct 250 ms 24172 KB Output is correct
7 Correct 267 ms 24172 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 72 ms 6380 KB Output is correct
10 Correct 254 ms 24172 KB Output is correct
11 Correct 255 ms 24300 KB Output is correct
12 Correct 258 ms 24172 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
16 Correct 64 ms 6508 KB Output is correct
17 Correct 251 ms 24172 KB Output is correct
18 Correct 280 ms 24300 KB Output is correct
19 Correct 253 ms 24300 KB Output is correct
20 Correct 259 ms 24172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 11 ms 1388 KB Output is correct
7 Correct 260 ms 24108 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 10 ms 1388 KB Output is correct
13 Correct 259 ms 24172 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 5 ms 876 KB Output is correct
17 Correct 120 ms 14188 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 0 ms 364 KB Output is correct
20 Correct 63 ms 6380 KB Output is correct
21 Correct 249 ms 24044 KB Output is correct
22 Correct 251 ms 24172 KB Output is correct
23 Correct 275 ms 24172 KB Output is correct
24 Correct 248 ms 24172 KB Output is correct
25 Correct 111 ms 14188 KB Output is correct
26 Correct 110 ms 14200 KB Output is correct
27 Correct 261 ms 24044 KB Output is correct
28 Correct 252 ms 24428 KB Output is correct
29 Correct 0 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 0 ms 364 KB Output is correct
32 Correct 0 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 0 ms 364 KB Output is correct
36 Correct 12 ms 1388 KB Output is correct
37 Correct 248 ms 24172 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 0 ms 364 KB Output is correct
40 Correct 11 ms 1388 KB Output is correct
41 Correct 252 ms 24184 KB Output is correct
42 Correct 0 ms 364 KB Output is correct
43 Correct 0 ms 364 KB Output is correct
44 Correct 5 ms 876 KB Output is correct
45 Correct 119 ms 14188 KB Output is correct
46 Correct 1 ms 492 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 69 ms 6636 KB Output is correct
50 Correct 250 ms 24300 KB Output is correct
51 Correct 253 ms 24320 KB Output is correct
52 Correct 267 ms 24172 KB Output is correct
53 Correct 115 ms 14188 KB Output is correct
54 Correct 110 ms 14188 KB Output is correct
55 Correct 250 ms 24192 KB Output is correct
56 Correct 258 ms 24172 KB Output is correct
57 Correct 112 ms 14444 KB Output is correct
58 Correct 0 ms 364 KB Output is correct
59 Correct 1 ms 364 KB Output is correct
60 Correct 5 ms 876 KB Output is correct
61 Correct 118 ms 14188 KB Output is correct
62 Correct 1 ms 364 KB Output is correct
63 Correct 1 ms 364 KB Output is correct
64 Correct 1 ms 364 KB Output is correct
65 Correct 63 ms 6380 KB Output is correct
66 Correct 116 ms 14188 KB Output is correct
67 Correct 111 ms 14188 KB Output is correct
68 Correct 113 ms 14444 KB Output is correct
69 Correct 108 ms 14188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 11 ms 1388 KB Output is correct
7 Correct 260 ms 24108 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 10 ms 1388 KB Output is correct
13 Correct 259 ms 24172 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 5 ms 876 KB Output is correct
17 Correct 120 ms 14188 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 0 ms 364 KB Output is correct
20 Correct 63 ms 6380 KB Output is correct
21 Correct 249 ms 24044 KB Output is correct
22 Correct 251 ms 24172 KB Output is correct
23 Correct 275 ms 24172 KB Output is correct
24 Correct 248 ms 24172 KB Output is correct
25 Correct 111 ms 14188 KB Output is correct
26 Correct 110 ms 14200 KB Output is correct
27 Correct 261 ms 24044 KB Output is correct
28 Correct 252 ms 24428 KB Output is correct
29 Correct 0 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 0 ms 364 KB Output is correct
32 Correct 0 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 0 ms 364 KB Output is correct
36 Correct 12 ms 1388 KB Output is correct
37 Correct 248 ms 24172 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 0 ms 364 KB Output is correct
40 Correct 11 ms 1388 KB Output is correct
41 Correct 252 ms 24184 KB Output is correct
42 Correct 0 ms 364 KB Output is correct
43 Correct 0 ms 364 KB Output is correct
44 Correct 5 ms 876 KB Output is correct
45 Correct 119 ms 14188 KB Output is correct
46 Correct 1 ms 492 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 69 ms 6636 KB Output is correct
50 Correct 250 ms 24300 KB Output is correct
51 Correct 253 ms 24320 KB Output is correct
52 Correct 267 ms 24172 KB Output is correct
53 Correct 115 ms 14188 KB Output is correct
54 Correct 110 ms 14188 KB Output is correct
55 Correct 250 ms 24192 KB Output is correct
56 Correct 258 ms 24172 KB Output is correct
57 Correct 112 ms 14444 KB Output is correct
58 Correct 1 ms 364 KB Output is correct
59 Correct 0 ms 364 KB Output is correct
60 Correct 0 ms 364 KB Output is correct
61 Correct 63 ms 6380 KB Output is correct
62 Correct 255 ms 24300 KB Output is correct
63 Correct 250 ms 24172 KB Output is correct
64 Correct 267 ms 24172 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Correct 72 ms 6380 KB Output is correct
67 Correct 254 ms 24172 KB Output is correct
68 Correct 255 ms 24300 KB Output is correct
69 Correct 258 ms 24172 KB Output is correct
70 Correct 0 ms 364 KB Output is correct
71 Correct 1 ms 364 KB Output is correct
72 Correct 0 ms 364 KB Output is correct
73 Correct 64 ms 6508 KB Output is correct
74 Correct 251 ms 24172 KB Output is correct
75 Correct 280 ms 24300 KB Output is correct
76 Correct 253 ms 24300 KB Output is correct
77 Correct 259 ms 24172 KB Output is correct
78 Correct 0 ms 364 KB Output is correct
79 Correct 1 ms 364 KB Output is correct
80 Correct 5 ms 876 KB Output is correct
81 Correct 118 ms 14188 KB Output is correct
82 Correct 1 ms 364 KB Output is correct
83 Correct 1 ms 364 KB Output is correct
84 Correct 1 ms 364 KB Output is correct
85 Correct 63 ms 6380 KB Output is correct
86 Correct 116 ms 14188 KB Output is correct
87 Correct 111 ms 14188 KB Output is correct
88 Correct 113 ms 14444 KB Output is correct
89 Correct 108 ms 14188 KB Output is correct
90 Correct 0 ms 364 KB Output is correct
91 Correct 0 ms 364 KB Output is correct
92 Correct 5 ms 876 KB Output is correct
93 Correct 115 ms 14316 KB Output is correct
94 Correct 0 ms 364 KB Output is correct
95 Correct 0 ms 364 KB Output is correct
96 Correct 1 ms 364 KB Output is correct
97 Correct 28 ms 3820 KB Output is correct
98 Correct 111 ms 14188 KB Output is correct
99 Correct 110 ms 14216 KB Output is correct
100 Correct 108 ms 14316 KB Output is correct
101 Correct 111 ms 14316 KB Output is correct
102 Correct 111 ms 14188 KB Output is correct
103 Correct 115 ms 14232 KB Output is correct
104 Correct 116 ms 14316 KB Output is correct
105 Correct 121 ms 14188 KB Output is correct