Submission #779271

# Submission time Handle Problem Language Result Execution time Memory
779271 2023-07-11T09:42:47 Z kamelfanger83 Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
158 ms 22632 KB
#include "supertrees.h"
#include <vector>
#include <cassert>
#include <numeric>

using namespace std;

template <typename T>
bool operator==(vector<T> &a, vector<T> &b){
    for (int i = 0; i < a.size(); ++i) {
        if (a[i] != b[i]) return false;
    }
    return true;
}

template <typename T>
bool operator!=(vector<T> &a, vector<T> &b){
    return !(a==b);
}

struct Unionfind {
    vector<int> group;
    Unionfind(int n) {
        group.resize(n);
        iota(group.begin(), group.end(), 0);
    }
    int find(int i){
        if (group[i] == i) return i;
        return group[i] = find(group[i]);
    }
    void merge(int a, int b){
        a = find(a); b = find(b);
        if (a == b) return;
        group[b] = group[a];
    }
};

int construct(vector<vector<int>> p) {
    int n = p.size();
    vector<vector<int>> res (n);
    vector<bool> inc (n);
    vector<bool> hasc (n);

    Unionfind unionfind (n);

    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            if (p[i][j] != 0) unionfind.merge(i, j);
        }
    }

    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            if ((p[i][j] == 0) && (unionfind.find(i) == unionfind.find(j))) return 0;
        }
    }

    for (int i = 0; i < n; ++i) {
        if (!res[i].empty()) continue;
        res[i].assign(n, 0);
        inc[i] = true;
        for (int j = 0; j < n; ++j) {
            if (p[i][j] == 0 || i == j) continue;
            if (p[i][j] == 1){
                if (p[i] != p[j]) return 0;
                res[j].assign(n, 0);
                res[j][i] = 1;
                res[i][j] = 1;
            }
            if (p[i][j] == 2) hasc[i] = true;
            if (p[i][j] == 3) return 0;
        }
    }

    for (int i = 0; i < n; ++i) {
        if (!inc[i] || !hasc[i]) continue;
        int ft = -1, lt = -1, bt = -1, at = -1;
        for (int j = 0; j < n; ++j) {
            if (i == j) continue;
            if (inc[j] && (unionfind.find(i) == unionfind.find(j))){
                if (p[i][j] != 2) return 0;
                if (ft == -1) ft = j;
                if (j < i) bt = j;
                if (j > i && at == -1) at = j;
                lt = j;
            }
        }
        if (lt == -1) return 0;
        if (at == -1) at = ft;
        if (bt == -1) bt = lt;
        if (at == bt) return 0;
        res[i][bt] = 1;
        res[i][at] = 1;
    }

    build(res);
    return 1;
}

Compilation message

supertrees.cpp: In instantiation of 'bool operator==(std::vector<T>&, std::vector<T>&) [with T = int]':
supertrees.cpp:18:15:   required from 'bool operator!=(std::vector<T>&, std::vector<T>&) [with T = int]'
supertrees.cpp:65:32:   required from here
supertrees.cpp:10:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     for (int i = 0; i < a.size(); ++i) {
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 6 ms 1108 KB Output is correct
7 Correct 148 ms 21916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 6 ms 1108 KB Output is correct
7 Correct 148 ms 21916 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 6 ms 1108 KB Output is correct
13 Correct 144 ms 22012 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 69 ms 8180 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 36 ms 5704 KB Output is correct
21 Correct 146 ms 22228 KB Output is correct
22 Correct 147 ms 22216 KB Output is correct
23 Correct 156 ms 22264 KB Output is correct
24 Correct 146 ms 22248 KB Output is correct
25 Correct 64 ms 8472 KB Output is correct
26 Correct 62 ms 8396 KB Output is correct
27 Correct 156 ms 22300 KB Output is correct
28 Correct 145 ms 22220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 9 ms 1088 KB Output is correct
9 Correct 145 ms 21984 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 6 ms 1172 KB Output is correct
13 Correct 157 ms 22540 KB Output is correct
14 Correct 1 ms 284 KB Output is correct
15 Correct 1 ms 284 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 71 ms 8704 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 41 ms 5920 KB Output is correct
22 Correct 154 ms 22492 KB Output is correct
23 Correct 151 ms 22516 KB Output is correct
24 Correct 157 ms 22540 KB Output is correct
25 Correct 67 ms 12264 KB Output is correct
26 Correct 66 ms 8460 KB Output is correct
27 Correct 152 ms 22632 KB Output is correct
28 Correct 158 ms 22476 KB Output is correct
29 Correct 66 ms 12296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 41 ms 5756 KB Output is correct
5 Correct 147 ms 22004 KB Output is correct
6 Correct 147 ms 22020 KB Output is correct
7 Correct 158 ms 21984 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 47 ms 5720 KB Output is correct
10 Correct 154 ms 22020 KB Output is correct
11 Correct 150 ms 21952 KB Output is correct
12 Correct 157 ms 22004 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 42 ms 5716 KB Output is correct
17 Correct 152 ms 22444 KB Output is correct
18 Correct 150 ms 22504 KB Output is correct
19 Correct 148 ms 22432 KB Output is correct
20 Correct 153 ms 22520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 6 ms 1108 KB Output is correct
7 Correct 148 ms 21916 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 6 ms 1108 KB Output is correct
13 Correct 144 ms 22012 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 69 ms 8180 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 36 ms 5704 KB Output is correct
21 Correct 146 ms 22228 KB Output is correct
22 Correct 147 ms 22216 KB Output is correct
23 Correct 156 ms 22264 KB Output is correct
24 Correct 146 ms 22248 KB Output is correct
25 Correct 64 ms 8472 KB Output is correct
26 Correct 62 ms 8396 KB Output is correct
27 Correct 156 ms 22300 KB Output is correct
28 Correct 145 ms 22220 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 9 ms 1088 KB Output is correct
37 Correct 145 ms 21984 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 6 ms 1172 KB Output is correct
41 Correct 157 ms 22540 KB Output is correct
42 Correct 1 ms 284 KB Output is correct
43 Correct 1 ms 284 KB Output is correct
44 Correct 3 ms 596 KB Output is correct
45 Correct 71 ms 8704 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 41 ms 5920 KB Output is correct
50 Correct 154 ms 22492 KB Output is correct
51 Correct 151 ms 22516 KB Output is correct
52 Correct 157 ms 22540 KB Output is correct
53 Correct 67 ms 12264 KB Output is correct
54 Correct 66 ms 8460 KB Output is correct
55 Correct 152 ms 22632 KB Output is correct
56 Correct 158 ms 22476 KB Output is correct
57 Correct 66 ms 12296 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 0 ms 284 KB Output is correct
60 Correct 3 ms 596 KB Output is correct
61 Correct 83 ms 9464 KB Output is correct
62 Correct 1 ms 212 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 38 ms 5984 KB Output is correct
66 Correct 64 ms 9420 KB Output is correct
67 Correct 65 ms 9488 KB Output is correct
68 Correct 62 ms 9388 KB Output is correct
69 Correct 66 ms 13320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 6 ms 1108 KB Output is correct
7 Correct 148 ms 21916 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 6 ms 1108 KB Output is correct
13 Correct 144 ms 22012 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 69 ms 8180 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 36 ms 5704 KB Output is correct
21 Correct 146 ms 22228 KB Output is correct
22 Correct 147 ms 22216 KB Output is correct
23 Correct 156 ms 22264 KB Output is correct
24 Correct 146 ms 22248 KB Output is correct
25 Correct 64 ms 8472 KB Output is correct
26 Correct 62 ms 8396 KB Output is correct
27 Correct 156 ms 22300 KB Output is correct
28 Correct 145 ms 22220 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 9 ms 1088 KB Output is correct
37 Correct 145 ms 21984 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 6 ms 1172 KB Output is correct
41 Correct 157 ms 22540 KB Output is correct
42 Correct 1 ms 284 KB Output is correct
43 Correct 1 ms 284 KB Output is correct
44 Correct 3 ms 596 KB Output is correct
45 Correct 71 ms 8704 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 41 ms 5920 KB Output is correct
50 Correct 154 ms 22492 KB Output is correct
51 Correct 151 ms 22516 KB Output is correct
52 Correct 157 ms 22540 KB Output is correct
53 Correct 67 ms 12264 KB Output is correct
54 Correct 66 ms 8460 KB Output is correct
55 Correct 152 ms 22632 KB Output is correct
56 Correct 158 ms 22476 KB Output is correct
57 Correct 66 ms 12296 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 41 ms 5756 KB Output is correct
62 Correct 147 ms 22004 KB Output is correct
63 Correct 147 ms 22020 KB Output is correct
64 Correct 158 ms 21984 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 47 ms 5720 KB Output is correct
67 Correct 154 ms 22020 KB Output is correct
68 Correct 150 ms 21952 KB Output is correct
69 Correct 157 ms 22004 KB Output is correct
70 Correct 0 ms 212 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 0 ms 212 KB Output is correct
73 Correct 42 ms 5716 KB Output is correct
74 Correct 152 ms 22444 KB Output is correct
75 Correct 150 ms 22504 KB Output is correct
76 Correct 148 ms 22432 KB Output is correct
77 Correct 153 ms 22520 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 0 ms 284 KB Output is correct
80 Correct 3 ms 596 KB Output is correct
81 Correct 83 ms 9464 KB Output is correct
82 Correct 1 ms 212 KB Output is correct
83 Correct 1 ms 212 KB Output is correct
84 Correct 0 ms 212 KB Output is correct
85 Correct 38 ms 5984 KB Output is correct
86 Correct 64 ms 9420 KB Output is correct
87 Correct 65 ms 9488 KB Output is correct
88 Correct 62 ms 9388 KB Output is correct
89 Correct 66 ms 13320 KB Output is correct
90 Correct 0 ms 288 KB Output is correct
91 Correct 1 ms 212 KB Output is correct
92 Correct 3 ms 596 KB Output is correct
93 Correct 68 ms 9384 KB Output is correct
94 Correct 0 ms 212 KB Output is correct
95 Correct 0 ms 212 KB Output is correct
96 Correct 0 ms 212 KB Output is correct
97 Correct 16 ms 2260 KB Output is correct
98 Correct 62 ms 8188 KB Output is correct
99 Correct 64 ms 8196 KB Output is correct
100 Correct 62 ms 8172 KB Output is correct
101 Correct 65 ms 9480 KB Output is correct
102 Correct 64 ms 8196 KB Output is correct
103 Correct 64 ms 8140 KB Output is correct
104 Correct 66 ms 8196 KB Output is correct
105 Correct 68 ms 8184 KB Output is correct