답안 #510568

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
510568 2022-01-15T01:54:01 Z tabr 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
325 ms 22104 KB
#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

void build(vector<vector<int>>);

struct dsu {
    vector<int> p;
    vector<int> sz;
    int n;

    dsu(int _n) : n(_n) {
        p.resize(n);
        iota(p.begin(), p.end(), 0);
        sz.assign(n, 1);
    }

    inline int get(int x) {
        if (p[x] == x) {
            return x;
        } else {
            return p[x] = get(p[x]);
        }
    }

    inline bool unite(int x, int y) {
        x = get(x);
        y = get(y);
        if (x == y) {
            return false;
        }
        if (sz[x] > sz[y]) {
            swap(x, y);
        }
        p[x] = y;
        sz[y] += sz[x];
        return true;
    }

    inline bool same(int x, int y) {
        return (get(x) == get(y));
    }
};

int construct(vector<vector<int>> p) {
    int n = (int) p.size();
    dsu uf1(n);
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (p[i][j] == 3) {
                return 0;
            }
            if (p[i][j] == 1) {
                uf1.unite(i, j);
            }
        }
    }
    vector<vector<int>> res(n, vector<int>(n));
    vector<vector<int>> c(n);
    for (int i = 0; i < n; i++) {
        c[uf1.get(i)].emplace_back(i);
    }
    for (int i = 0; i < n; i++) {
        for (int j = 1; j < (int) c[i].size(); j++) {
            res[c[i][0]][c[i][j]] = res[c[i][j]][c[i][0]] = 1;
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (p[i][j] != p[uf1.get(i)][uf1.get(j)]) {
                return 0;
            }
        }
    }
    dsu uf2(n);
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (uf1.get(i) == i && uf1.get(j) == j && p[i][j] == 2) {
                uf2.unite(i, j);
            }
        }
    }
    c = vector<vector<int>>(n);
    for (int i = 0; i < n; i++) {
        if (uf1.get(i) == i) {
            c[uf2.get(i)].emplace_back(i);
        }
    }
    for (int i = 0; i < n; i++) {
        int sz = (int) c[i].size();
        if (sz == 0 || sz == 1) {
            continue;
        }
        if (sz == 2) {
            return 0;
        }
        for (int j = 0; j < sz; j++) {
            res[c[i][j]][c[i][(j + 1) % sz]] = res[c[i][(j + 1) % sz]][c[i][j]] = 1;
        }
        for (int x = 0; x < sz; x++) {
            for (int y = x + 1; y < sz; y++) {
                if (p[c[i][x]][c[i][y]] != 2) {
                    return 0;
                }
            }
        }
    }
    build(res);
    return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 13 ms 1140 KB Output is correct
7 Correct 265 ms 22016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 13 ms 1140 KB Output is correct
7 Correct 265 ms 22016 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 10 ms 1152 KB Output is correct
13 Correct 246 ms 21996 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 9 ms 716 KB Output is correct
17 Correct 173 ms 12036 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 224 KB Output is correct
20 Correct 65 ms 5760 KB Output is correct
21 Correct 258 ms 22020 KB Output is correct
22 Correct 257 ms 22000 KB Output is correct
23 Correct 252 ms 22028 KB Output is correct
24 Correct 258 ms 22076 KB Output is correct
25 Correct 125 ms 12180 KB Output is correct
26 Correct 69 ms 12156 KB Output is correct
27 Correct 206 ms 22008 KB Output is correct
28 Correct 208 ms 22012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 16 ms 1176 KB Output is correct
9 Correct 269 ms 22100 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 7 ms 1100 KB Output is correct
13 Correct 199 ms 22064 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 4 ms 704 KB Output is correct
17 Correct 87 ms 12156 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 43 ms 5744 KB Output is correct
22 Correct 218 ms 21976 KB Output is correct
23 Correct 295 ms 22060 KB Output is correct
24 Correct 183 ms 22020 KB Output is correct
25 Correct 77 ms 12156 KB Output is correct
26 Correct 74 ms 12160 KB Output is correct
27 Correct 186 ms 22036 KB Output is correct
28 Correct 232 ms 22084 KB Output is correct
29 Correct 99 ms 12152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 44 ms 5760 KB Output is correct
5 Correct 272 ms 22072 KB Output is correct
6 Correct 230 ms 22008 KB Output is correct
7 Correct 307 ms 22036 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 54 ms 5700 KB Output is correct
10 Correct 204 ms 22044 KB Output is correct
11 Correct 207 ms 22012 KB Output is correct
12 Correct 325 ms 22016 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 58 ms 5700 KB Output is correct
17 Correct 224 ms 22072 KB Output is correct
18 Correct 324 ms 22104 KB Output is correct
19 Correct 198 ms 22008 KB Output is correct
20 Correct 207 ms 22024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 13 ms 1140 KB Output is correct
7 Correct 265 ms 22016 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 10 ms 1152 KB Output is correct
13 Correct 246 ms 21996 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 9 ms 716 KB Output is correct
17 Correct 173 ms 12036 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 224 KB Output is correct
20 Correct 65 ms 5760 KB Output is correct
21 Correct 258 ms 22020 KB Output is correct
22 Correct 257 ms 22000 KB Output is correct
23 Correct 252 ms 22028 KB Output is correct
24 Correct 258 ms 22076 KB Output is correct
25 Correct 125 ms 12180 KB Output is correct
26 Correct 69 ms 12156 KB Output is correct
27 Correct 206 ms 22008 KB Output is correct
28 Correct 208 ms 22012 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 0 ms 204 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 16 ms 1176 KB Output is correct
37 Correct 269 ms 22100 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 7 ms 1100 KB Output is correct
41 Correct 199 ms 22064 KB Output is correct
42 Correct 0 ms 204 KB Output is correct
43 Correct 0 ms 204 KB Output is correct
44 Correct 4 ms 704 KB Output is correct
45 Correct 87 ms 12156 KB Output is correct
46 Correct 0 ms 204 KB Output is correct
47 Correct 0 ms 204 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 43 ms 5744 KB Output is correct
50 Correct 218 ms 21976 KB Output is correct
51 Correct 295 ms 22060 KB Output is correct
52 Correct 183 ms 22020 KB Output is correct
53 Correct 77 ms 12156 KB Output is correct
54 Correct 74 ms 12160 KB Output is correct
55 Correct 186 ms 22036 KB Output is correct
56 Correct 232 ms 22084 KB Output is correct
57 Correct 99 ms 12152 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 7 ms 716 KB Output is correct
61 Correct 97 ms 12152 KB Output is correct
62 Correct 1 ms 204 KB Output is correct
63 Correct 0 ms 204 KB Output is correct
64 Correct 1 ms 204 KB Output is correct
65 Correct 42 ms 5756 KB Output is correct
66 Correct 84 ms 12164 KB Output is correct
67 Correct 107 ms 12168 KB Output is correct
68 Correct 113 ms 12156 KB Output is correct
69 Correct 82 ms 12152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 13 ms 1140 KB Output is correct
7 Correct 265 ms 22016 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 10 ms 1152 KB Output is correct
13 Correct 246 ms 21996 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 9 ms 716 KB Output is correct
17 Correct 173 ms 12036 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 224 KB Output is correct
20 Correct 65 ms 5760 KB Output is correct
21 Correct 258 ms 22020 KB Output is correct
22 Correct 257 ms 22000 KB Output is correct
23 Correct 252 ms 22028 KB Output is correct
24 Correct 258 ms 22076 KB Output is correct
25 Correct 125 ms 12180 KB Output is correct
26 Correct 69 ms 12156 KB Output is correct
27 Correct 206 ms 22008 KB Output is correct
28 Correct 208 ms 22012 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 0 ms 204 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 16 ms 1176 KB Output is correct
37 Correct 269 ms 22100 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 7 ms 1100 KB Output is correct
41 Correct 199 ms 22064 KB Output is correct
42 Correct 0 ms 204 KB Output is correct
43 Correct 0 ms 204 KB Output is correct
44 Correct 4 ms 704 KB Output is correct
45 Correct 87 ms 12156 KB Output is correct
46 Correct 0 ms 204 KB Output is correct
47 Correct 0 ms 204 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 43 ms 5744 KB Output is correct
50 Correct 218 ms 21976 KB Output is correct
51 Correct 295 ms 22060 KB Output is correct
52 Correct 183 ms 22020 KB Output is correct
53 Correct 77 ms 12156 KB Output is correct
54 Correct 74 ms 12160 KB Output is correct
55 Correct 186 ms 22036 KB Output is correct
56 Correct 232 ms 22084 KB Output is correct
57 Correct 99 ms 12152 KB Output is correct
58 Correct 0 ms 204 KB Output is correct
59 Correct 0 ms 204 KB Output is correct
60 Correct 0 ms 204 KB Output is correct
61 Correct 44 ms 5760 KB Output is correct
62 Correct 272 ms 22072 KB Output is correct
63 Correct 230 ms 22008 KB Output is correct
64 Correct 307 ms 22036 KB Output is correct
65 Correct 1 ms 204 KB Output is correct
66 Correct 54 ms 5700 KB Output is correct
67 Correct 204 ms 22044 KB Output is correct
68 Correct 207 ms 22012 KB Output is correct
69 Correct 325 ms 22016 KB Output is correct
70 Correct 1 ms 204 KB Output is correct
71 Correct 1 ms 256 KB Output is correct
72 Correct 1 ms 204 KB Output is correct
73 Correct 58 ms 5700 KB Output is correct
74 Correct 224 ms 22072 KB Output is correct
75 Correct 324 ms 22104 KB Output is correct
76 Correct 198 ms 22008 KB Output is correct
77 Correct 207 ms 22024 KB Output is correct
78 Correct 1 ms 204 KB Output is correct
79 Correct 1 ms 204 KB Output is correct
80 Correct 7 ms 716 KB Output is correct
81 Correct 97 ms 12152 KB Output is correct
82 Correct 1 ms 204 KB Output is correct
83 Correct 0 ms 204 KB Output is correct
84 Correct 1 ms 204 KB Output is correct
85 Correct 42 ms 5756 KB Output is correct
86 Correct 84 ms 12164 KB Output is correct
87 Correct 107 ms 12168 KB Output is correct
88 Correct 113 ms 12156 KB Output is correct
89 Correct 82 ms 12152 KB Output is correct
90 Correct 0 ms 204 KB Output is correct
91 Correct 1 ms 204 KB Output is correct
92 Correct 8 ms 628 KB Output is correct
93 Correct 75 ms 8060 KB Output is correct
94 Correct 1 ms 204 KB Output is correct
95 Correct 0 ms 204 KB Output is correct
96 Correct 1 ms 204 KB Output is correct
97 Correct 19 ms 2252 KB Output is correct
98 Correct 89 ms 8064 KB Output is correct
99 Correct 110 ms 8060 KB Output is correct
100 Correct 93 ms 8056 KB Output is correct
101 Correct 112 ms 8056 KB Output is correct
102 Correct 93 ms 8060 KB Output is correct
103 Correct 97 ms 10092 KB Output is correct
104 Correct 75 ms 10116 KB Output is correct
105 Correct 100 ms 10088 KB Output is correct