답안 #321426

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
321426 2020-11-12T09:59:35 Z grt 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
302 ms 28140 KB
#include <bits/stdc++.h>

using namespace std;

using vi = vector<int>;
using ll = long long;
using pi = pair<int,int>;

#define ST first
#define ND second
#define PB push_back

const int nax = 1000 + 10;
int n;
vi Graph[nax];
bool visited[nax];
vector<vi>comp;
vector<vi>access;
vi cur;

void build(vector<vi>v);

void dfs(int x) {
    visited[x] = 1;
    cur.PB(x);
    for(int nbh : Graph[x]) {
        if(!visited[nbh]) dfs(nbh);
    }
}

int construct(vector<vi> p) {
    int cnt3 = 0;
    n = (int)p.size();
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= n; ++j) {
            if(p[i - 1][j - 1] == 1) {
                Graph[i].PB(j);
            }
            if(p[i - 1][j - 1] == 3) cnt3++;
        }
    }
    if(cnt3 > 0) return 0;
    bool ok = 1;
    for(int i = 1; i <= n; ++i) {
        if(!visited[i]) {
            cur = {};
            dfs(i);
            comp.PB(cur);
            for(int x : cur) {
                for(int y : cur) {
                    if(p[x - 1][y - 1] != 1) ok = 0;
                }
            }
        }
    }
    if(!ok) return 0;
    for(auto c : comp) {
        cur = {};
        int id = 0;
        for(auto c2 : comp) {
            if(c2 == c) {
                cur.PB(id);
                id++;
                continue;
            }
            int cnt0 = 0, cnt1 = 0, cnt2 = 0;
            for(int x : c) {
                for(int y : c2) {
                    if(p[x - 1][y - 1] == 0) cnt0++;
                    else if(p[x - 1][y - 1] == 1) cnt1++;
                    else if(p[x - 1][y - 1] == 2) cnt2++;
                }
            }
            assert(cnt1 == 0);
            if(cnt0 > 0 && cnt2 > 0) ok = 0;
            if(cnt2 > 0) {
                cur.PB(id);
            }
            id++;
        }
        access.PB(cur);
        if((int)cur.size() == 2) ok = 0;
    }
    if(!ok) return 0;
    for(int i = 0; i <= n; ++i) visited[i] = 0;
    for(int i = 0; i < (int)comp.size(); ++i) {
        if(!visited[i]) {
            cur = access[i];
            visited[i] = 1;
            for(int x : cur) {
                visited[x] = 1;
                if(cur != access[x]) ok = 0;
            }
        }
    }
    if(!ok) return 0;
    vector<vi>g(n);
    for(int i = 0; i < n; ++i) g[i].resize(n);
    for(int nr = 0; nr < (int)access.size(); ++nr) {
        for(int i = 0; i < (int)comp[nr].size() - 1; ++i) {
           g[comp[nr][i] - 1][comp[nr][i + 1] - 1] = g[comp[nr][i + 1] - 1][comp[nr][i] - 1] = 1;
        }
        //cout << nr << " ";
        if((int)access[nr].size() == 1) continue;
        for(int i = 0; i < (int)access[nr].size(); ++i) {
            if(access[nr][i] == nr) {
                int pr = i - 1;
                if(pr < 0) pr = (int)access[nr].size() - 1;
                g[comp[access[nr][pr]][0] - 1][comp[nr][0] - 1] = g[comp[nr][0] - 1][comp[access[nr][pr]][0] - 1] = 1;
            }
        }
    }
    build(g);
    //for(int i = 0; i < n; ++i) {
    //    for(int j = 0; j < n; ++j) {
    //        cout << g[i][j] << " ";
    //    }
    //    cout << "\n";
    //}
    return 1;
}

//int main() {
    //cout << construct({{1, 1, 2, 2}, {1, 1, 2, 2}, {2, 2, 1, 2}, {2, 2, 2, 1}});
    //cout << construct({{1,3},{3,1}});
//}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 11 ms 1388 KB Output is correct
7 Correct 245 ms 26348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 11 ms 1388 KB Output is correct
7 Correct 245 ms 26348 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 13 ms 1280 KB Output is correct
13 Correct 289 ms 22252 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 748 KB Output is correct
17 Correct 114 ms 10732 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 0 ms 364 KB Output is correct
20 Correct 63 ms 5868 KB Output is correct
21 Correct 252 ms 22636 KB Output is correct
22 Correct 257 ms 22380 KB Output is correct
23 Correct 258 ms 24300 KB Output is correct
24 Correct 282 ms 22380 KB Output is correct
25 Correct 103 ms 8812 KB Output is correct
26 Correct 107 ms 8300 KB Output is correct
27 Correct 256 ms 25196 KB Output is correct
28 Correct 297 ms 22508 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 1 ms 364 KB Output is correct
4 Correct 1 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 1 ms 364 KB Output is correct
8 Correct 12 ms 1388 KB Output is correct
9 Correct 294 ms 24172 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 12 ms 1516 KB Output is correct
13 Correct 282 ms 28140 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 7 ms 876 KB Output is correct
17 Correct 154 ms 12268 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 74 ms 6380 KB Output is correct
22 Correct 293 ms 24616 KB Output is correct
23 Correct 292 ms 24424 KB Output is correct
24 Correct 296 ms 26220 KB Output is correct
25 Correct 138 ms 10348 KB Output is correct
26 Correct 141 ms 10732 KB Output is correct
27 Correct 300 ms 24172 KB Output is correct
28 Correct 299 ms 26220 KB Output is correct
29 Correct 136 ms 10348 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 64 ms 5868 KB Output is correct
5 Correct 253 ms 22636 KB Output is correct
6 Correct 257 ms 22252 KB Output is correct
7 Correct 260 ms 24300 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 72 ms 6380 KB Output is correct
10 Correct 285 ms 24572 KB Output is correct
11 Correct 289 ms 24172 KB Output is correct
12 Correct 302 ms 26348 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 71 ms 6380 KB Output is correct
17 Correct 292 ms 24556 KB Output is correct
18 Correct 268 ms 24300 KB Output is correct
19 Correct 267 ms 24316 KB Output is correct
20 Correct 292 ms 24300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 11 ms 1388 KB Output is correct
7 Correct 245 ms 26348 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 13 ms 1280 KB Output is correct
13 Correct 289 ms 22252 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 748 KB Output is correct
17 Correct 114 ms 10732 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 0 ms 364 KB Output is correct
20 Correct 63 ms 5868 KB Output is correct
21 Correct 252 ms 22636 KB Output is correct
22 Correct 257 ms 22380 KB Output is correct
23 Correct 258 ms 24300 KB Output is correct
24 Correct 282 ms 22380 KB Output is correct
25 Correct 103 ms 8812 KB Output is correct
26 Correct 107 ms 8300 KB Output is correct
27 Correct 256 ms 25196 KB Output is correct
28 Correct 297 ms 22508 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 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 1 ms 364 KB Output is correct
36 Correct 12 ms 1388 KB Output is correct
37 Correct 294 ms 24172 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 12 ms 1516 KB Output is correct
41 Correct 282 ms 28140 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 7 ms 876 KB Output is correct
45 Correct 154 ms 12268 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 74 ms 6380 KB Output is correct
50 Correct 293 ms 24616 KB Output is correct
51 Correct 292 ms 24424 KB Output is correct
52 Correct 296 ms 26220 KB Output is correct
53 Correct 138 ms 10348 KB Output is correct
54 Correct 141 ms 10732 KB Output is correct
55 Correct 300 ms 24172 KB Output is correct
56 Correct 299 ms 26220 KB Output is correct
57 Correct 136 ms 10348 KB Output is correct
58 Correct 1 ms 364 KB Output is correct
59 Correct 1 ms 364 KB Output is correct
60 Correct 8 ms 876 KB Output is correct
61 Correct 109 ms 12396 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 69 ms 6380 KB Output is correct
66 Correct 145 ms 10732 KB Output is correct
67 Correct 102 ms 10220 KB Output is correct
68 Correct 113 ms 10476 KB Output is correct
69 Correct 137 ms 10348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 11 ms 1388 KB Output is correct
7 Correct 245 ms 26348 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 13 ms 1280 KB Output is correct
13 Correct 289 ms 22252 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 748 KB Output is correct
17 Correct 114 ms 10732 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 0 ms 364 KB Output is correct
20 Correct 63 ms 5868 KB Output is correct
21 Correct 252 ms 22636 KB Output is correct
22 Correct 257 ms 22380 KB Output is correct
23 Correct 258 ms 24300 KB Output is correct
24 Correct 282 ms 22380 KB Output is correct
25 Correct 103 ms 8812 KB Output is correct
26 Correct 107 ms 8300 KB Output is correct
27 Correct 256 ms 25196 KB Output is correct
28 Correct 297 ms 22508 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 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 1 ms 364 KB Output is correct
36 Correct 12 ms 1388 KB Output is correct
37 Correct 294 ms 24172 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 12 ms 1516 KB Output is correct
41 Correct 282 ms 28140 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 7 ms 876 KB Output is correct
45 Correct 154 ms 12268 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 74 ms 6380 KB Output is correct
50 Correct 293 ms 24616 KB Output is correct
51 Correct 292 ms 24424 KB Output is correct
52 Correct 296 ms 26220 KB Output is correct
53 Correct 138 ms 10348 KB Output is correct
54 Correct 141 ms 10732 KB Output is correct
55 Correct 300 ms 24172 KB Output is correct
56 Correct 299 ms 26220 KB Output is correct
57 Correct 136 ms 10348 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 64 ms 5868 KB Output is correct
62 Correct 253 ms 22636 KB Output is correct
63 Correct 257 ms 22252 KB Output is correct
64 Correct 260 ms 24300 KB Output is correct
65 Correct 1 ms 512 KB Output is correct
66 Correct 72 ms 6380 KB Output is correct
67 Correct 285 ms 24572 KB Output is correct
68 Correct 289 ms 24172 KB Output is correct
69 Correct 302 ms 26348 KB Output is correct
70 Correct 1 ms 364 KB Output is correct
71 Correct 1 ms 364 KB Output is correct
72 Correct 1 ms 364 KB Output is correct
73 Correct 71 ms 6380 KB Output is correct
74 Correct 292 ms 24556 KB Output is correct
75 Correct 268 ms 24300 KB Output is correct
76 Correct 267 ms 24316 KB Output is correct
77 Correct 292 ms 24300 KB Output is correct
78 Correct 1 ms 364 KB Output is correct
79 Correct 1 ms 364 KB Output is correct
80 Correct 8 ms 876 KB Output is correct
81 Correct 109 ms 12396 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 69 ms 6380 KB Output is correct
86 Correct 145 ms 10732 KB Output is correct
87 Correct 102 ms 10220 KB Output is correct
88 Correct 113 ms 10476 KB Output is correct
89 Correct 137 ms 10348 KB Output is correct
90 Correct 1 ms 364 KB Output is correct
91 Correct 1 ms 364 KB Output is correct
92 Correct 5 ms 748 KB Output is correct
93 Correct 111 ms 11524 KB Output is correct
94 Correct 1 ms 492 KB Output is correct
95 Correct 1 ms 364 KB Output is correct
96 Correct 1 ms 364 KB Output is correct
97 Correct 26 ms 2796 KB Output is correct
98 Correct 101 ms 10220 KB Output is correct
99 Correct 106 ms 10220 KB Output is correct
100 Correct 103 ms 10348 KB Output is correct
101 Correct 100 ms 10220 KB Output is correct
102 Correct 91 ms 10252 KB Output is correct
103 Correct 96 ms 10220 KB Output is correct
104 Correct 98 ms 12652 KB Output is correct
105 Correct 111 ms 10348 KB Output is correct