Submission #300471

# Submission time Handle Problem Language Result Execution time Memory
300471 2020-09-17T07:43:27 Z imeimi2000 Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
278 ms 26232 KB
#ifdef imeimi

#include <vector>

int construct(std::vector<std::vector<int>> p);
void build(std::vector<std::vector<int>> b);

#include <vector>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <string>
#define n N

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() {
    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);
}

#undef n
#else

#include "supertrees.h"

#endif

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;

static vector<int> lst;
static int n, edge[1000][1000];
static bool vis[1000];
static int idx[1000];
static void dfs(int x, int c) {
    vis[x] = 1;
    lst.push_back(x);
    for (int i = 0; i < n; ++i) {
        if (!edge[x][i] || edge[x][i] > c || vis[i]) continue;
        dfs(i, c);
    }
}

int construct(vector<vector<int>> p) {
	n = p.size();
    for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) {
        if (p[i][j] == 3) return 0;
        edge[i][j] = p[i][j];
    }
	vector<vector<int>> ans(n, vector<int>(n, 0));
    for (int i = 0; i < n; ++i) {
        if (vis[i]) continue;
        dfs(i, 1);
        for (int j : lst) for (int k : lst) if (edge[j][k] != 1) return 0;
        for (int j : lst) idx[j] = lst[0];
        for (int j = 1; j < int(lst.size()); ++j) {
            int x = lst[j - 1], y = lst[j];
            ans[x][y] = ans[y][x] = 1;
        }
        lst.clear();
    }
    memset(vis, 0, sizeof(vis));
    for (int i = 0; i < n; ++i) {
        if (vis[i]) continue;
        dfs(i, 2);
        for (int j : lst) for (int k : lst) if (!edge[j][k]) return 0;
        vector<int> nxt;
        for (int j : lst) if (idx[j] == j) nxt.push_back(j);
        lst.clear();
        if (int(nxt.size()) == 2) return 0;
        if (int(nxt.size()) <= 1) continue;
        for (int j = 0; j < int(nxt.size()); ++j) {
            int x = nxt[j], y = nxt[(j + 1) % int(nxt.size())];
            ans[x][y] = ans[y][x] = 1;
        }
    }
    build(ans);
    return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 2048 KB Output is correct
7 Correct 250 ms 26104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 2048 KB Output is correct
7 Correct 250 ms 26104 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 11 ms 2048 KB Output is correct
13 Correct 243 ms 26104 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 5 ms 1536 KB Output is correct
17 Correct 114 ms 16120 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 65 ms 7928 KB Output is correct
21 Correct 251 ms 25976 KB Output is correct
22 Correct 250 ms 25976 KB Output is correct
23 Correct 258 ms 26104 KB Output is correct
24 Correct 248 ms 25976 KB Output is correct
25 Correct 102 ms 16120 KB Output is correct
26 Correct 103 ms 16120 KB Output is correct
27 Correct 260 ms 25976 KB Output is correct
28 Correct 265 ms 25976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 11 ms 2048 KB Output is correct
9 Correct 246 ms 26104 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 11 ms 2048 KB Output is correct
13 Correct 251 ms 26108 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 1664 KB Output is correct
17 Correct 123 ms 16120 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 62 ms 7800 KB Output is correct
22 Correct 247 ms 25976 KB Output is correct
23 Correct 243 ms 26104 KB Output is correct
24 Correct 278 ms 25976 KB Output is correct
25 Correct 103 ms 16092 KB Output is correct
26 Correct 104 ms 16120 KB Output is correct
27 Correct 243 ms 25976 KB Output is correct
28 Correct 259 ms 26104 KB Output is correct
29 Correct 99 ms 16120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 63 ms 7800 KB Output is correct
5 Correct 247 ms 25976 KB Output is correct
6 Correct 246 ms 26104 KB Output is correct
7 Correct 257 ms 26232 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 66 ms 7800 KB Output is correct
10 Correct 245 ms 25976 KB Output is correct
11 Correct 247 ms 25980 KB Output is correct
12 Correct 263 ms 26104 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 63 ms 7800 KB Output is correct
17 Correct 249 ms 25980 KB Output is correct
18 Correct 253 ms 25976 KB Output is correct
19 Correct 246 ms 25976 KB Output is correct
20 Correct 245 ms 25976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 2048 KB Output is correct
7 Correct 250 ms 26104 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 11 ms 2048 KB Output is correct
13 Correct 243 ms 26104 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 5 ms 1536 KB Output is correct
17 Correct 114 ms 16120 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 65 ms 7928 KB Output is correct
21 Correct 251 ms 25976 KB Output is correct
22 Correct 250 ms 25976 KB Output is correct
23 Correct 258 ms 26104 KB Output is correct
24 Correct 248 ms 25976 KB Output is correct
25 Correct 102 ms 16120 KB Output is correct
26 Correct 103 ms 16120 KB Output is correct
27 Correct 260 ms 25976 KB Output is correct
28 Correct 265 ms 25976 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 11 ms 2048 KB Output is correct
37 Correct 246 ms 26104 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 11 ms 2048 KB Output is correct
41 Correct 251 ms 26108 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 6 ms 1664 KB Output is correct
45 Correct 123 ms 16120 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 62 ms 7800 KB Output is correct
50 Correct 247 ms 25976 KB Output is correct
51 Correct 243 ms 26104 KB Output is correct
52 Correct 278 ms 25976 KB Output is correct
53 Correct 103 ms 16092 KB Output is correct
54 Correct 104 ms 16120 KB Output is correct
55 Correct 243 ms 25976 KB Output is correct
56 Correct 259 ms 26104 KB Output is correct
57 Correct 99 ms 16120 KB Output is correct
58 Correct 0 ms 384 KB Output is correct
59 Correct 1 ms 384 KB Output is correct
60 Correct 6 ms 1536 KB Output is correct
61 Correct 116 ms 16120 KB Output is correct
62 Correct 1 ms 384 KB Output is correct
63 Correct 1 ms 512 KB Output is correct
64 Correct 1 ms 384 KB Output is correct
65 Correct 62 ms 7800 KB Output is correct
66 Correct 103 ms 16120 KB Output is correct
67 Correct 104 ms 16120 KB Output is correct
68 Correct 100 ms 16124 KB Output is correct
69 Correct 103 ms 16120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 2048 KB Output is correct
7 Correct 250 ms 26104 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 11 ms 2048 KB Output is correct
13 Correct 243 ms 26104 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 5 ms 1536 KB Output is correct
17 Correct 114 ms 16120 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 65 ms 7928 KB Output is correct
21 Correct 251 ms 25976 KB Output is correct
22 Correct 250 ms 25976 KB Output is correct
23 Correct 258 ms 26104 KB Output is correct
24 Correct 248 ms 25976 KB Output is correct
25 Correct 102 ms 16120 KB Output is correct
26 Correct 103 ms 16120 KB Output is correct
27 Correct 260 ms 25976 KB Output is correct
28 Correct 265 ms 25976 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 11 ms 2048 KB Output is correct
37 Correct 246 ms 26104 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 11 ms 2048 KB Output is correct
41 Correct 251 ms 26108 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 6 ms 1664 KB Output is correct
45 Correct 123 ms 16120 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 62 ms 7800 KB Output is correct
50 Correct 247 ms 25976 KB Output is correct
51 Correct 243 ms 26104 KB Output is correct
52 Correct 278 ms 25976 KB Output is correct
53 Correct 103 ms 16092 KB Output is correct
54 Correct 104 ms 16120 KB Output is correct
55 Correct 243 ms 25976 KB Output is correct
56 Correct 259 ms 26104 KB Output is correct
57 Correct 99 ms 16120 KB Output is correct
58 Correct 1 ms 384 KB Output is correct
59 Correct 1 ms 384 KB Output is correct
60 Correct 1 ms 384 KB Output is correct
61 Correct 63 ms 7800 KB Output is correct
62 Correct 247 ms 25976 KB Output is correct
63 Correct 246 ms 26104 KB Output is correct
64 Correct 257 ms 26232 KB Output is correct
65 Correct 1 ms 384 KB Output is correct
66 Correct 66 ms 7800 KB Output is correct
67 Correct 245 ms 25976 KB Output is correct
68 Correct 247 ms 25980 KB Output is correct
69 Correct 263 ms 26104 KB Output is correct
70 Correct 1 ms 384 KB Output is correct
71 Correct 1 ms 384 KB Output is correct
72 Correct 1 ms 384 KB Output is correct
73 Correct 63 ms 7800 KB Output is correct
74 Correct 249 ms 25980 KB Output is correct
75 Correct 253 ms 25976 KB Output is correct
76 Correct 246 ms 25976 KB Output is correct
77 Correct 245 ms 25976 KB Output is correct
78 Correct 0 ms 384 KB Output is correct
79 Correct 1 ms 384 KB Output is correct
80 Correct 6 ms 1536 KB Output is correct
81 Correct 116 ms 16120 KB Output is correct
82 Correct 1 ms 384 KB Output is correct
83 Correct 1 ms 512 KB Output is correct
84 Correct 1 ms 384 KB Output is correct
85 Correct 62 ms 7800 KB Output is correct
86 Correct 103 ms 16120 KB Output is correct
87 Correct 104 ms 16120 KB Output is correct
88 Correct 100 ms 16124 KB Output is correct
89 Correct 103 ms 16120 KB Output is correct
90 Correct 1 ms 256 KB Output is correct
91 Correct 1 ms 256 KB Output is correct
92 Correct 5 ms 768 KB Output is correct
93 Correct 103 ms 8184 KB Output is correct
94 Correct 1 ms 256 KB Output is correct
95 Correct 1 ms 384 KB Output is correct
96 Correct 1 ms 384 KB Output is correct
97 Correct 24 ms 2432 KB Output is correct
98 Correct 93 ms 8440 KB Output is correct
99 Correct 94 ms 8824 KB Output is correct
100 Correct 94 ms 8568 KB Output is correct
101 Correct 94 ms 9468 KB Output is correct
102 Correct 100 ms 8184 KB Output is correct
103 Correct 97 ms 8184 KB Output is correct
104 Correct 98 ms 8188 KB Output is correct
105 Correct 101 ms 8188 KB Output is correct