답안 #1050138

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1050138 2024-08-09T07:39:19 Z dozer 슈퍼트리 잇기 (IOI20_supertrees) C++14
96 / 100
108 ms 24148 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++) {
        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 344 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 93 ms 22100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 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 93 ms 22100 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 4 ms 1116 KB Output is correct
13 Correct 93 ms 22044 KB Output is correct
14 Correct 0 ms 344 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 12116 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 24 ms 5860 KB Output is correct
21 Correct 95 ms 22100 KB Output is correct
22 Correct 96 ms 22092 KB Output is correct
23 Correct 98 ms 22044 KB Output is correct
24 Correct 102 ms 22096 KB Output is correct
25 Correct 43 ms 12124 KB Output is correct
26 Correct 40 ms 12112 KB Output is correct
27 Correct 96 ms 22096 KB Output is correct
28 Correct 94 ms 22096 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 1184 KB Output is correct
9 Correct 100 ms 23888 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 1372 KB Output is correct
13 Correct 97 ms 23916 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 47 ms 14088 KB Output is correct
18 Correct 1 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 26 ms 6228 KB Output is correct
22 Correct 99 ms 24068 KB Output is correct
23 Correct 93 ms 24148 KB Output is correct
24 Correct 99 ms 24144 KB Output is correct
25 Correct 43 ms 14164 KB Output is correct
26 Correct 44 ms 14164 KB Output is correct
27 Correct 98 ms 24020 KB Output is correct
28 Correct 108 ms 24148 KB Output is correct
29 Correct 44 ms 14416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 28 ms 5784 KB Output is correct
5 Correct 94 ms 22096 KB Output is correct
6 Correct 93 ms 22100 KB Output is correct
7 Correct 97 ms 22020 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 23 ms 5724 KB Output is correct
10 Correct 93 ms 22044 KB Output is correct
11 Correct 95 ms 22044 KB Output is correct
12 Correct 101 ms 22104 KB Output is correct
13 Correct 0 ms 348 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 5724 KB Output is correct
17 Correct 94 ms 22100 KB Output is correct
18 Correct 98 ms 22036 KB Output is correct
19 Correct 98 ms 22096 KB Output is correct
20 Correct 98 ms 22100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 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 93 ms 22100 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 4 ms 1116 KB Output is correct
13 Correct 93 ms 22044 KB Output is correct
14 Correct 0 ms 344 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 12116 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 24 ms 5860 KB Output is correct
21 Correct 95 ms 22100 KB Output is correct
22 Correct 96 ms 22092 KB Output is correct
23 Correct 98 ms 22044 KB Output is correct
24 Correct 102 ms 22096 KB Output is correct
25 Correct 43 ms 12124 KB Output is correct
26 Correct 40 ms 12112 KB Output is correct
27 Correct 96 ms 22096 KB Output is correct
28 Correct 94 ms 22096 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 1184 KB Output is correct
37 Correct 100 ms 23888 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 1372 KB Output is correct
41 Correct 97 ms 23916 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 2 ms 860 KB Output is correct
45 Correct 47 ms 14088 KB Output is correct
46 Correct 1 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 26 ms 6228 KB Output is correct
50 Correct 99 ms 24068 KB Output is correct
51 Correct 93 ms 24148 KB Output is correct
52 Correct 99 ms 24144 KB Output is correct
53 Correct 43 ms 14164 KB Output is correct
54 Correct 44 ms 14164 KB Output is correct
55 Correct 98 ms 24020 KB Output is correct
56 Correct 108 ms 24148 KB Output is correct
57 Correct 44 ms 14416 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 44 ms 12056 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 24 ms 5780 KB Output is correct
66 Correct 42 ms 12056 KB Output is correct
67 Correct 42 ms 12116 KB Output is correct
68 Correct 41 ms 12116 KB Output is correct
69 Correct 41 ms 12116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 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 93 ms 22100 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 4 ms 1116 KB Output is correct
13 Correct 93 ms 22044 KB Output is correct
14 Correct 0 ms 344 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 12116 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 24 ms 5860 KB Output is correct
21 Correct 95 ms 22100 KB Output is correct
22 Correct 96 ms 22092 KB Output is correct
23 Correct 98 ms 22044 KB Output is correct
24 Correct 102 ms 22096 KB Output is correct
25 Correct 43 ms 12124 KB Output is correct
26 Correct 40 ms 12112 KB Output is correct
27 Correct 96 ms 22096 KB Output is correct
28 Correct 94 ms 22096 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 1184 KB Output is correct
37 Correct 100 ms 23888 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 1372 KB Output is correct
41 Correct 97 ms 23916 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 2 ms 860 KB Output is correct
45 Correct 47 ms 14088 KB Output is correct
46 Correct 1 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 26 ms 6228 KB Output is correct
50 Correct 99 ms 24068 KB Output is correct
51 Correct 93 ms 24148 KB Output is correct
52 Correct 99 ms 24144 KB Output is correct
53 Correct 43 ms 14164 KB Output is correct
54 Correct 44 ms 14164 KB Output is correct
55 Correct 98 ms 24020 KB Output is correct
56 Correct 108 ms 24148 KB Output is correct
57 Correct 44 ms 14416 KB Output is correct
58 Correct 0 ms 344 KB Output is correct
59 Correct 0 ms 344 KB Output is correct
60 Correct 0 ms 344 KB Output is correct
61 Correct 28 ms 5784 KB Output is correct
62 Correct 94 ms 22096 KB Output is correct
63 Correct 93 ms 22100 KB Output is correct
64 Correct 97 ms 22020 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 23 ms 5724 KB Output is correct
67 Correct 93 ms 22044 KB Output is correct
68 Correct 95 ms 22044 KB Output is correct
69 Correct 101 ms 22104 KB Output is correct
70 Correct 0 ms 348 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 5724 KB Output is correct
74 Correct 94 ms 22100 KB Output is correct
75 Correct 98 ms 22036 KB Output is correct
76 Correct 98 ms 22096 KB Output is correct
77 Correct 98 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 44 ms 12056 KB Output is correct
82 Correct 0 ms 348 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 24 ms 5780 KB Output is correct
86 Correct 42 ms 12056 KB Output is correct
87 Correct 42 ms 12116 KB Output is correct
88 Correct 41 ms 12116 KB Output is correct
89 Correct 41 ms 12116 KB Output is correct
90 Correct 0 ms 344 KB Output is correct
91 Correct 0 ms 344 KB Output is correct
92 Correct 2 ms 860 KB Output is correct
93 Correct 43 ms 12056 KB Output is correct
94 Correct 0 ms 348 KB Output is correct
95 Correct 0 ms 348 KB Output is correct
96 Correct 0 ms 348 KB Output is correct
97 Correct 11 ms 3420 KB Output is correct
98 Correct 47 ms 12060 KB Output is correct
99 Correct 42 ms 12080 KB Output is correct
100 Correct 41 ms 12052 KB Output is correct
101 Incorrect 103 ms 22024 KB Answer gives possible 1 while actual possible 0
102 Halted 0 ms 0 KB -