답안 #536382

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
536382 2022-03-13T06:56:59 Z ddy888 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
199 ms 28168 KB
#undef _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define fi first
#define si second
#define ar array
typedef pair<int,int> pi;
typedef tuple<int,int,int> ti;  
void debug_out() {cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {cerr<<" "<<to_string(H);debug_out(T...);}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)

#include "supertrees.h"

int N;
int A[1010][1010], branch[1010];
vector<vector<int> > ans;
set<int> adj[1010];

struct dsu {    
    int par[1010];
    void init(int x) {for (int i = 0; i <= x; ++i) par[i] = i;}
    int root(int x) { return (par[x]==x)? x:par[x]=root(par[x]); }
    bool same(int a, int b) { return root(a) == root(b); }
    void merge(int a, int b) { // b absorbs a
        if (same(a, b)) return;
        par[root(a)] = root(b);
    }
};

void join(int x, int y) {
    if (x == y) return;
    ans[x - 1][y - 1] = 1;
    ans[y - 1][x - 1] = 1;
}

int construct(std::vector<std::vector<int>> p) {
    N = p.size();
    ans.resize(N, vector<int>(N));
    dsu one, two;
    one.init(N), two.init(N);
    for (int i = 1; i <= N; ++i) for (int j = 1; j <= N; ++j) A[i][j] = p[i - 1][j - 1];
    for (int i = 1; i <= N; ++i) {
        for (int j = i + 1; j <= N; ++j) {
            if (A[i][j] == 3) return 0;
            if (A[i][j] == 2) two.merge(i, j);
            if (A[i][j] == 1) {
                join(one.root(i), one.root(j));
                one.merge(one.root(i), one.root(j));
            }
        }
    }
    for (int i = 1; i <= N; ++i) branch[i] = (one.root(i) != i);
    for (int i = 1; i <= N; ++i) adj[two.root(i)].insert(i);
    for (int i = 1; i <= N; ++i) {
        if ((int)adj[i].size() < 2) continue;
        vector<int> nodes;
        for (auto j: adj[i]) {
            if (branch[j]) continue;
            nodes.pb(j);
        }
        if ((int)nodes.size() <= 2) return 0;
        int cnt = 0;
        for (auto j: nodes) {
            for (auto k: nodes) {
                if (j == k) continue;
                cnt += (A[j][k] == 2);
            }
        }
        int sz = (int)nodes.size();
        if (cnt != sz * (sz - 1)) return 0;
        for (int j = 1; j < (int)nodes.size(); ++j) join(nodes[j], nodes[j - 1]);
        join(nodes[0], nodes.back());
    }
    for (int i = 1; i <= N; ++i) {
        for (int j = i + 1; j <= N; ++j) {
            if (A[i][j] == 0 && (one.same(i, j) || two.same(i, j))) return 0;
        }
    }
    build(ans);
    return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 352 KB Output is correct
6 Correct 8 ms 2076 KB Output is correct
7 Correct 179 ms 27996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 352 KB Output is correct
6 Correct 8 ms 2076 KB Output is correct
7 Correct 179 ms 27996 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 12 ms 2032 KB Output is correct
13 Correct 175 ms 28080 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 1620 KB Output is correct
17 Correct 83 ms 18148 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 43 ms 8196 KB Output is correct
21 Correct 187 ms 28020 KB Output is correct
22 Correct 174 ms 27948 KB Output is correct
23 Correct 199 ms 27980 KB Output is correct
24 Correct 182 ms 27968 KB Output is correct
25 Correct 75 ms 18112 KB Output is correct
26 Correct 74 ms 18096 KB Output is correct
27 Correct 180 ms 28076 KB Output is correct
28 Correct 176 ms 28088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 9 ms 2052 KB Output is correct
9 Correct 174 ms 26056 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 9 ms 2004 KB Output is correct
13 Correct 176 ms 26104 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 1620 KB Output is correct
17 Correct 81 ms 16188 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 46 ms 7748 KB Output is correct
22 Correct 182 ms 26052 KB Output is correct
23 Correct 173 ms 26044 KB Output is correct
24 Correct 188 ms 26120 KB Output is correct
25 Correct 74 ms 16196 KB Output is correct
26 Correct 74 ms 16184 KB Output is correct
27 Correct 175 ms 26056 KB Output is correct
28 Correct 182 ms 26172 KB Output is correct
29 Correct 73 ms 16188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 46 ms 8224 KB Output is correct
5 Correct 174 ms 27960 KB Output is correct
6 Correct 174 ms 27964 KB Output is correct
7 Correct 182 ms 28080 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 47 ms 8240 KB Output is correct
10 Correct 176 ms 27964 KB Output is correct
11 Correct 184 ms 27972 KB Output is correct
12 Correct 195 ms 28132 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 45 ms 8228 KB Output is correct
17 Correct 174 ms 27968 KB Output is correct
18 Correct 179 ms 28168 KB Output is correct
19 Correct 176 ms 27968 KB Output is correct
20 Correct 175 ms 27980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 352 KB Output is correct
6 Correct 8 ms 2076 KB Output is correct
7 Correct 179 ms 27996 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 12 ms 2032 KB Output is correct
13 Correct 175 ms 28080 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 1620 KB Output is correct
17 Correct 83 ms 18148 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 43 ms 8196 KB Output is correct
21 Correct 187 ms 28020 KB Output is correct
22 Correct 174 ms 27948 KB Output is correct
23 Correct 199 ms 27980 KB Output is correct
24 Correct 182 ms 27968 KB Output is correct
25 Correct 75 ms 18112 KB Output is correct
26 Correct 74 ms 18096 KB Output is correct
27 Correct 180 ms 28076 KB Output is correct
28 Correct 176 ms 28088 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 9 ms 2052 KB Output is correct
37 Correct 174 ms 26056 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 9 ms 2004 KB Output is correct
41 Correct 176 ms 26104 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 4 ms 1620 KB Output is correct
45 Correct 81 ms 16188 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 46 ms 7748 KB Output is correct
50 Correct 182 ms 26052 KB Output is correct
51 Correct 173 ms 26044 KB Output is correct
52 Correct 188 ms 26120 KB Output is correct
53 Correct 74 ms 16196 KB Output is correct
54 Correct 74 ms 16184 KB Output is correct
55 Correct 175 ms 26056 KB Output is correct
56 Correct 182 ms 26172 KB Output is correct
57 Correct 73 ms 16188 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 4 ms 1620 KB Output is correct
61 Correct 89 ms 18108 KB Output is correct
62 Correct 1 ms 352 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 0 ms 356 KB Output is correct
65 Correct 46 ms 8396 KB Output is correct
66 Correct 79 ms 18220 KB Output is correct
67 Correct 73 ms 18092 KB Output is correct
68 Correct 72 ms 18096 KB Output is correct
69 Correct 72 ms 18100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 352 KB Output is correct
6 Correct 8 ms 2076 KB Output is correct
7 Correct 179 ms 27996 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 12 ms 2032 KB Output is correct
13 Correct 175 ms 28080 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 1620 KB Output is correct
17 Correct 83 ms 18148 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 43 ms 8196 KB Output is correct
21 Correct 187 ms 28020 KB Output is correct
22 Correct 174 ms 27948 KB Output is correct
23 Correct 199 ms 27980 KB Output is correct
24 Correct 182 ms 27968 KB Output is correct
25 Correct 75 ms 18112 KB Output is correct
26 Correct 74 ms 18096 KB Output is correct
27 Correct 180 ms 28076 KB Output is correct
28 Correct 176 ms 28088 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 9 ms 2052 KB Output is correct
37 Correct 174 ms 26056 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 9 ms 2004 KB Output is correct
41 Correct 176 ms 26104 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 4 ms 1620 KB Output is correct
45 Correct 81 ms 16188 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 46 ms 7748 KB Output is correct
50 Correct 182 ms 26052 KB Output is correct
51 Correct 173 ms 26044 KB Output is correct
52 Correct 188 ms 26120 KB Output is correct
53 Correct 74 ms 16196 KB Output is correct
54 Correct 74 ms 16184 KB Output is correct
55 Correct 175 ms 26056 KB Output is correct
56 Correct 182 ms 26172 KB Output is correct
57 Correct 73 ms 16188 KB Output is correct
58 Correct 0 ms 340 KB Output is correct
59 Correct 0 ms 340 KB Output is correct
60 Correct 0 ms 340 KB Output is correct
61 Correct 46 ms 8224 KB Output is correct
62 Correct 174 ms 27960 KB Output is correct
63 Correct 174 ms 27964 KB Output is correct
64 Correct 182 ms 28080 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 47 ms 8240 KB Output is correct
67 Correct 176 ms 27964 KB Output is correct
68 Correct 184 ms 27972 KB Output is correct
69 Correct 195 ms 28132 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 45 ms 8228 KB Output is correct
74 Correct 174 ms 27968 KB Output is correct
75 Correct 179 ms 28168 KB Output is correct
76 Correct 176 ms 27968 KB Output is correct
77 Correct 175 ms 27980 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 1 ms 340 KB Output is correct
80 Correct 4 ms 1620 KB Output is correct
81 Correct 89 ms 18108 KB Output is correct
82 Correct 1 ms 352 KB Output is correct
83 Correct 1 ms 340 KB Output is correct
84 Correct 0 ms 356 KB Output is correct
85 Correct 46 ms 8396 KB Output is correct
86 Correct 79 ms 18220 KB Output is correct
87 Correct 73 ms 18092 KB Output is correct
88 Correct 72 ms 18096 KB Output is correct
89 Correct 72 ms 18100 KB Output is correct
90 Correct 1 ms 340 KB Output is correct
91 Correct 1 ms 340 KB Output is correct
92 Correct 6 ms 1620 KB Output is correct
93 Correct 87 ms 18096 KB Output is correct
94 Correct 1 ms 340 KB Output is correct
95 Correct 1 ms 340 KB Output is correct
96 Correct 1 ms 340 KB Output is correct
97 Correct 19 ms 5808 KB Output is correct
98 Correct 70 ms 18044 KB Output is correct
99 Correct 72 ms 18024 KB Output is correct
100 Correct 73 ms 18092 KB Output is correct
101 Correct 74 ms 18096 KB Output is correct
102 Correct 72 ms 18100 KB Output is correct
103 Correct 74 ms 18096 KB Output is correct
104 Correct 76 ms 18096 KB Output is correct
105 Correct 77 ms 18096 KB Output is correct