답안 #1050143

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1050143 2024-08-09T07:40:36 Z dozer 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
165 ms 22352 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define sp " "
#define endl "\n"
#define LL node * 2
#define RR node * 2 + 1
#define ll long long
#define N 200005

const int modulo = 1e9 + 7;
const ll INF = 2e18 + 7;


int construct(std::vector<std::vector<int>> p) {
    int n = p.size();
    vector<vector<int>> adj(n, vector<int>(n, 0));
    vector<int> done(n, 0), done2(n, 0), root(n, 0);
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            if (p[i][j] == 3) return 0;
        
    for (int i = 0; i < n; i++) {
        if (done[i]) continue;
        done[i] = 1;
        root[i] = 1;
        for (int j = 0; j < n; j++){
            if (j == i) continue;
            if (p[i][j] == 1){
                if (done[j]) return 0;
                for (int k = 0; k < n; k++){
                    if (k == i || k == j) continue;
                    if (p[i][k] != p[j][k]) return 0;
                }
                done[j] = 1;
                adj[i][j] = 1;
                adj[j][i] = 1;
            }
        }
    }



    for (int i = 0; i < n; i++){
        if (root[i] == 0 || done2[i]) continue;
        vector<int> tmp;
        tmp.pb(i);
        done2[i] = 1;
        for (int j = 0; j < n; j++){
            if (j == i || root[j] == 0 || p[i][j] != 2) continue;
            if (done2[j]) {
                return 0;
            }
            for (int k = 0; k < n; k++){
                if (k == i || k == j) continue;
                if (root[k] == 1 && p[i][k] != p[j][k]) {
                    return 0;
                }
            }
            tmp.pb(j);
            done2[j] = 1;
        }
        int m = tmp.size();
        if (m == 1) continue;
        if (m == 2) return 0;
        for (int j = 0; j < m; j++){
            int curr = tmp[j], nxt = tmp[(j + 1) % m];
            adj[curr][nxt] = 1;
            adj[nxt][curr] = 1;
        }
    }

    build(adj);
    return 1;
}
/*
static int n;
static std::vector<std::vector<int>> p;
static std::vector<std::vector<int>> b;
static bool called = false;

static void check(bool cond, std::string message) {
    if (!cond) {
        printf("%s\n", message.c_str());
        fclose(stdout);
        exit(0);
    }
}

void build(std::vector<std::vector<int>> _b) {
    check(!called, "build is called more than once");
    called = true;
    check((int)_b.size() == n, "Invalid number of rows in b");
    for (int i = 0; i < n; i++) {
        check((int)_b[i].size() == n, "Invalid number of columns in b");
    }
    b = _b;
}

int main() {
    fileio();
    assert(scanf("%d", &n) == 1);
    
    p.resize(n);
    for (int i = 0; i < n; i++) {
        p[i].resize(n);
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            assert(scanf("%d", &p[i][j]) == 1);
        }
    }
    fclose(stdin);

    int possible = construct(p);

    check(possible == 0 || possible == 1, "Invalid return value of construct");
    if (possible == 1) {
        check(called, "construct returned 1 without calling build");
    } else {
        check(!called, "construct called build but returned 0");
    }

    printf("%d\n", possible);
    if (possible == 1) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (j) {
                    printf(" ");
                }
                printf("%d", b[i][j]);
            }
            printf("\n");
        }
    }
    fclose(stdout);
}
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 4 ms 1116 KB Output is correct
7 Correct 94 ms 22144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 4 ms 1116 KB Output is correct
7 Correct 94 ms 22144 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 8 ms 1116 KB Output is correct
13 Correct 165 ms 22188 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 45 ms 12112 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 28 ms 5912 KB Output is correct
21 Correct 108 ms 22176 KB Output is correct
22 Correct 96 ms 22100 KB Output is correct
23 Correct 100 ms 22096 KB Output is correct
24 Correct 95 ms 22100 KB Output is correct
25 Correct 40 ms 12116 KB Output is correct
26 Correct 39 ms 12112 KB Output is correct
27 Correct 105 ms 22040 KB Output is correct
28 Correct 99 ms 22100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 4 ms 1116 KB Output is correct
9 Correct 95 ms 22032 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 4 ms 1116 KB Output is correct
13 Correct 97 ms 22100 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 924 KB Output is correct
17 Correct 47 ms 12112 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 33 ms 5680 KB Output is correct
22 Correct 108 ms 22100 KB Output is correct
23 Correct 95 ms 22144 KB Output is correct
24 Correct 107 ms 22100 KB Output is correct
25 Correct 41 ms 12116 KB Output is correct
26 Correct 42 ms 12116 KB Output is correct
27 Correct 106 ms 22112 KB Output is correct
28 Correct 102 ms 22352 KB Output is correct
29 Correct 41 ms 12056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 28 ms 5712 KB Output is correct
5 Correct 96 ms 22096 KB Output is correct
6 Correct 94 ms 22036 KB Output is correct
7 Correct 101 ms 22096 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 24 ms 5736 KB Output is correct
10 Correct 94 ms 22096 KB Output is correct
11 Correct 94 ms 22036 KB Output is correct
12 Correct 98 ms 22040 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 23 ms 5784 KB Output is correct
17 Correct 114 ms 22100 KB Output is correct
18 Correct 109 ms 22096 KB Output is correct
19 Correct 111 ms 22100 KB Output is correct
20 Correct 93 ms 22100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 4 ms 1116 KB Output is correct
7 Correct 94 ms 22144 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 8 ms 1116 KB Output is correct
13 Correct 165 ms 22188 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 45 ms 12112 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 28 ms 5912 KB Output is correct
21 Correct 108 ms 22176 KB Output is correct
22 Correct 96 ms 22100 KB Output is correct
23 Correct 100 ms 22096 KB Output is correct
24 Correct 95 ms 22100 KB Output is correct
25 Correct 40 ms 12116 KB Output is correct
26 Correct 39 ms 12112 KB Output is correct
27 Correct 105 ms 22040 KB Output is correct
28 Correct 99 ms 22100 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 4 ms 1116 KB Output is correct
37 Correct 95 ms 22032 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 4 ms 1116 KB Output is correct
41 Correct 97 ms 22100 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 2 ms 924 KB Output is correct
45 Correct 47 ms 12112 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 33 ms 5680 KB Output is correct
50 Correct 108 ms 22100 KB Output is correct
51 Correct 95 ms 22144 KB Output is correct
52 Correct 107 ms 22100 KB Output is correct
53 Correct 41 ms 12116 KB Output is correct
54 Correct 42 ms 12116 KB Output is correct
55 Correct 106 ms 22112 KB Output is correct
56 Correct 102 ms 22352 KB Output is correct
57 Correct 41 ms 12056 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 2 ms 860 KB Output is correct
61 Correct 45 ms 12056 KB Output is correct
62 Correct 0 ms 344 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 29 ms 5848 KB Output is correct
66 Correct 41 ms 12116 KB Output is correct
67 Correct 41 ms 12056 KB Output is correct
68 Correct 53 ms 12112 KB Output is correct
69 Correct 40 ms 12116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 4 ms 1116 KB Output is correct
7 Correct 94 ms 22144 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 8 ms 1116 KB Output is correct
13 Correct 165 ms 22188 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 45 ms 12112 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 28 ms 5912 KB Output is correct
21 Correct 108 ms 22176 KB Output is correct
22 Correct 96 ms 22100 KB Output is correct
23 Correct 100 ms 22096 KB Output is correct
24 Correct 95 ms 22100 KB Output is correct
25 Correct 40 ms 12116 KB Output is correct
26 Correct 39 ms 12112 KB Output is correct
27 Correct 105 ms 22040 KB Output is correct
28 Correct 99 ms 22100 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 4 ms 1116 KB Output is correct
37 Correct 95 ms 22032 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 4 ms 1116 KB Output is correct
41 Correct 97 ms 22100 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 2 ms 924 KB Output is correct
45 Correct 47 ms 12112 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 33 ms 5680 KB Output is correct
50 Correct 108 ms 22100 KB Output is correct
51 Correct 95 ms 22144 KB Output is correct
52 Correct 107 ms 22100 KB Output is correct
53 Correct 41 ms 12116 KB Output is correct
54 Correct 42 ms 12116 KB Output is correct
55 Correct 106 ms 22112 KB Output is correct
56 Correct 102 ms 22352 KB Output is correct
57 Correct 41 ms 12056 KB Output is correct
58 Correct 1 ms 600 KB Output is correct
59 Correct 0 ms 344 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 28 ms 5712 KB Output is correct
62 Correct 96 ms 22096 KB Output is correct
63 Correct 94 ms 22036 KB Output is correct
64 Correct 101 ms 22096 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 24 ms 5736 KB Output is correct
67 Correct 94 ms 22096 KB Output is correct
68 Correct 94 ms 22036 KB Output is correct
69 Correct 98 ms 22040 KB Output is correct
70 Correct 1 ms 344 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 23 ms 5784 KB Output is correct
74 Correct 114 ms 22100 KB Output is correct
75 Correct 109 ms 22096 KB Output is correct
76 Correct 111 ms 22100 KB Output is correct
77 Correct 93 ms 22100 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 0 ms 348 KB Output is correct
80 Correct 2 ms 860 KB Output is correct
81 Correct 45 ms 12056 KB Output is correct
82 Correct 0 ms 344 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 29 ms 5848 KB Output is correct
86 Correct 41 ms 12116 KB Output is correct
87 Correct 41 ms 12056 KB Output is correct
88 Correct 53 ms 12112 KB Output is correct
89 Correct 40 ms 12116 KB Output is correct
90 Correct 0 ms 344 KB Output is correct
91 Correct 0 ms 348 KB Output is correct
92 Correct 2 ms 860 KB Output is correct
93 Correct 48 ms 12052 KB Output is correct
94 Correct 0 ms 344 KB Output is correct
95 Correct 0 ms 348 KB Output is correct
96 Correct 0 ms 348 KB Output is correct
97 Correct 10 ms 3220 KB Output is correct
98 Correct 80 ms 12056 KB Output is correct
99 Correct 40 ms 12112 KB Output is correct
100 Correct 39 ms 12112 KB Output is correct
101 Correct 45 ms 12112 KB Output is correct
102 Correct 40 ms 12116 KB Output is correct
103 Correct 38 ms 12112 KB Output is correct
104 Correct 39 ms 12052 KB Output is correct
105 Correct 46 ms 12112 KB Output is correct