Submission #1066373

# Submission time Handle Problem Language Result Execution time Memory
1066373 2024-08-19T19:23:56 Z allin27x Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
168 ms 24148 KB
#include <bits/stdc++.h>
using namespace std;


void build(vector<vector<int>> b);

int solve(vector<vector<int>> &p, vector<int> &rel, vector<vector<int>> &b) {
    vector<vector<int>> cmp;
    vector<int> cp(p.size(), 0);
    for (int i: rel) {
        int c = -1;
        for (int j = 0; j < cmp.size(); j++) {
            for (int x: cmp[j]) {
                if (p[i][x] == 1) c = j;
            }
        }
        for (int j = 0; j < cmp.size(); j++) {
            for (int x: cmp[j]) {
                if ((p[i][x]==1)  ^ (j==c)) return 0;
            }
        }
        if (c==-1) cmp.push_back({i}), cp[i] = cmp.size()-1; else cmp[c].push_back(i),cp[i] = c;
    }
    for (int i: rel) for (int j: rel) {
        if (cp[i] == cp[j] && p[i][j] != 1) return 0;
        if (cp[i] != cp[j] && p[i][j] != 2) return 0;
    }
    for (auto cm: cmp) {
        for (int i=0; i<cm.size()-1; i++) {
            b[cm[i]][cm[i+1]] = 1;
            b[cm[i+1]][cm[i]] = 1;
        }
    }
    if (cmp.size() == 2) return 0;
    if (cmp.size() == 1) return 1;
    for (int j=0; j<cmp.size()-1; j++) {
        b[cmp[j][0]][cmp[j+1][0]] = 1;
        b[cmp[j+1][0]][cmp[j][0]] = 1;
    }
    b[cmp[0][0]][cmp.back()[0]] = 1;
    b[cmp.back()[0]][cmp[0][0]] = 1;
    return 1;
}

int construct(vector<vector<int>> p) {
    int n = p.size();
    for (int i = 0; i < n; i++) for (int j = 0; j < p[i].size(); j++) if (p[i][j] != p[j][i]) return 0;
    for (int i = 0; i<n; i++) if (p[i][i] != 1) return 0;
    vector<vector<int>> b(n, vector<int>(n, 0));
    vector<vector<int>> cmp;
    for (int i = 0; i < n; i++) {
        int c = -1;
        for (int j = 0; j < cmp.size(); j++) {
            for (int x: cmp[j]) {
                if (p[i][x]) c = j;
            }
        }
        for (int j = 0; j < cmp.size(); j++) {
            for (int x: cmp[j]) {
                if ((p[i][x]!=0)  ^ (j==c)) return 0;
            }
        }
        if (c==-1) cmp.push_back({i}); else cmp[c].push_back(i);
    }
    for (auto cm: cmp) if (!solve(p, cm, b)) return 0;
    build(b);
    return 1;
}

Compilation message

supertrees.cpp: In function 'int solve(std::vector<std::vector<int> >&, std::vector<int>&, std::vector<std::vector<int> >&)':
supertrees.cpp:12:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |         for (int j = 0; j < cmp.size(); j++) {
      |                         ~~^~~~~~~~~~~~
supertrees.cpp:17:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |         for (int j = 0; j < cmp.size(); j++) {
      |                         ~~^~~~~~~~~~~~
supertrees.cpp:29:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         for (int i=0; i<cm.size()-1; i++) {
      |                       ~^~~~~~~~~~~~
supertrees.cpp:36:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for (int j=0; j<cmp.size()-1; j++) {
      |                   ~^~~~~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:47:51: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for (int i = 0; i < n; i++) for (int j = 0; j < p[i].size(); j++) if (p[i][j] != p[j][i]) return 0;
      |                                                 ~~^~~~~~~~~~~~~
supertrees.cpp:53:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         for (int j = 0; j < cmp.size(); j++) {
      |                         ~~^~~~~~~~~~~~
supertrees.cpp:58:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |         for (int j = 0; j < cmp.size(); j++) {
      |                         ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 10 ms 1372 KB Output is correct
7 Correct 166 ms 24068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 10 ms 1372 KB Output is correct
7 Correct 166 ms 24068 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 7 ms 1372 KB Output is correct
13 Correct 120 ms 24076 KB Output is correct
14 Correct 1 ms 440 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 56 ms 14104 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 30 ms 6360 KB Output is correct
21 Correct 130 ms 24076 KB Output is correct
22 Correct 160 ms 24052 KB Output is correct
23 Correct 136 ms 24068 KB Output is correct
24 Correct 168 ms 24148 KB Output is correct
25 Correct 59 ms 14164 KB Output is correct
26 Correct 51 ms 14164 KB Output is correct
27 Correct 126 ms 24016 KB Output is correct
28 Correct 119 ms 24148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 5 ms 1192 KB Output is correct
9 Correct 123 ms 23812 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 6 ms 1372 KB Output is correct
13 Correct 125 ms 24124 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 95 ms 14084 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 31 ms 6232 KB Output is correct
22 Correct 139 ms 24092 KB Output is correct
23 Correct 118 ms 23948 KB Output is correct
24 Correct 130 ms 24148 KB Output is correct
25 Correct 53 ms 14164 KB Output is correct
26 Correct 53 ms 14084 KB Output is correct
27 Correct 117 ms 23944 KB Output is correct
28 Correct 131 ms 23972 KB Output is correct
29 Correct 52 ms 14168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 32 ms 6308 KB Output is correct
5 Correct 134 ms 23944 KB Output is correct
6 Correct 127 ms 23940 KB Output is correct
7 Correct 154 ms 23932 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 29 ms 6208 KB Output is correct
10 Correct 145 ms 24148 KB Output is correct
11 Correct 129 ms 23888 KB Output is correct
12 Correct 127 ms 23944 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 29 ms 6224 KB Output is correct
17 Correct 126 ms 24068 KB Output is correct
18 Correct 115 ms 24144 KB Output is correct
19 Correct 127 ms 24144 KB Output is correct
20 Correct 125 ms 24068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 10 ms 1372 KB Output is correct
7 Correct 166 ms 24068 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 7 ms 1372 KB Output is correct
13 Correct 120 ms 24076 KB Output is correct
14 Correct 1 ms 440 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 56 ms 14104 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 30 ms 6360 KB Output is correct
21 Correct 130 ms 24076 KB Output is correct
22 Correct 160 ms 24052 KB Output is correct
23 Correct 136 ms 24068 KB Output is correct
24 Correct 168 ms 24148 KB Output is correct
25 Correct 59 ms 14164 KB Output is correct
26 Correct 51 ms 14164 KB Output is correct
27 Correct 126 ms 24016 KB Output is correct
28 Correct 119 ms 24148 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 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 5 ms 1192 KB Output is correct
37 Correct 123 ms 23812 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 6 ms 1372 KB Output is correct
41 Correct 125 ms 24124 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 3 ms 860 KB Output is correct
45 Correct 95 ms 14084 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 31 ms 6232 KB Output is correct
50 Correct 139 ms 24092 KB Output is correct
51 Correct 118 ms 23948 KB Output is correct
52 Correct 130 ms 24148 KB Output is correct
53 Correct 53 ms 14164 KB Output is correct
54 Correct 53 ms 14084 KB Output is correct
55 Correct 117 ms 23944 KB Output is correct
56 Correct 131 ms 23972 KB Output is correct
57 Correct 52 ms 14168 KB Output is correct
58 Correct 0 ms 344 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 3 ms 856 KB Output is correct
61 Correct 58 ms 14088 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 29 ms 6312 KB Output is correct
66 Correct 55 ms 14160 KB Output is correct
67 Correct 55 ms 14084 KB Output is correct
68 Correct 52 ms 14164 KB Output is correct
69 Correct 55 ms 14084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 10 ms 1372 KB Output is correct
7 Correct 166 ms 24068 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 7 ms 1372 KB Output is correct
13 Correct 120 ms 24076 KB Output is correct
14 Correct 1 ms 440 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 56 ms 14104 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 30 ms 6360 KB Output is correct
21 Correct 130 ms 24076 KB Output is correct
22 Correct 160 ms 24052 KB Output is correct
23 Correct 136 ms 24068 KB Output is correct
24 Correct 168 ms 24148 KB Output is correct
25 Correct 59 ms 14164 KB Output is correct
26 Correct 51 ms 14164 KB Output is correct
27 Correct 126 ms 24016 KB Output is correct
28 Correct 119 ms 24148 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 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 5 ms 1192 KB Output is correct
37 Correct 123 ms 23812 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 6 ms 1372 KB Output is correct
41 Correct 125 ms 24124 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 3 ms 860 KB Output is correct
45 Correct 95 ms 14084 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 31 ms 6232 KB Output is correct
50 Correct 139 ms 24092 KB Output is correct
51 Correct 118 ms 23948 KB Output is correct
52 Correct 130 ms 24148 KB Output is correct
53 Correct 53 ms 14164 KB Output is correct
54 Correct 53 ms 14084 KB Output is correct
55 Correct 117 ms 23944 KB Output is correct
56 Correct 131 ms 23972 KB Output is correct
57 Correct 52 ms 14168 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 32 ms 6308 KB Output is correct
62 Correct 134 ms 23944 KB Output is correct
63 Correct 127 ms 23940 KB Output is correct
64 Correct 154 ms 23932 KB Output is correct
65 Correct 0 ms 344 KB Output is correct
66 Correct 29 ms 6208 KB Output is correct
67 Correct 145 ms 24148 KB Output is correct
68 Correct 129 ms 23888 KB Output is correct
69 Correct 127 ms 23944 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 29 ms 6224 KB Output is correct
74 Correct 126 ms 24068 KB Output is correct
75 Correct 115 ms 24144 KB Output is correct
76 Correct 127 ms 24144 KB Output is correct
77 Correct 125 ms 24068 KB Output is correct
78 Correct 0 ms 344 KB Output is correct
79 Correct 1 ms 348 KB Output is correct
80 Correct 3 ms 856 KB Output is correct
81 Correct 58 ms 14088 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 29 ms 6312 KB Output is correct
86 Correct 55 ms 14160 KB Output is correct
87 Correct 55 ms 14084 KB Output is correct
88 Correct 52 ms 14164 KB Output is correct
89 Correct 55 ms 14084 KB Output is correct
90 Correct 1 ms 348 KB Output is correct
91 Correct 0 ms 348 KB Output is correct
92 Correct 3 ms 1116 KB Output is correct
93 Correct 60 ms 14088 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 14 ms 3844 KB Output is correct
98 Correct 51 ms 14216 KB Output is correct
99 Correct 51 ms 14212 KB Output is correct
100 Correct 51 ms 14084 KB Output is correct
101 Correct 55 ms 14164 KB Output is correct
102 Correct 52 ms 14164 KB Output is correct
103 Correct 50 ms 14228 KB Output is correct
104 Correct 53 ms 14164 KB Output is correct
105 Correct 58 ms 14072 KB Output is correct