Submission #769102

# Submission time Handle Problem Language Result Execution time Memory
769102 2023-06-29T07:37:26 Z t6twotwo Connecting Supertrees (IOI20_supertrees) C++17
96 / 100
191 ms 23948 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
int construct(std::vector<std::vector<int>> a) {
    int N = a.size();
    vector<bool> vis(N);
    auto bfs = [&](int s, int t) {
        vector<int> v;
        queue<int> q;
        q.push(s);
        vis[s] = 1;
        while (!q.empty()) {
            int x = q.front();
            q.pop();
            v.push_back(x);
            for (int y = 0; y < N; y++) {
                if (!vis[y] && a[x][y] == t) {
                    vis[y] = 1;
                    q.push(y);
                }
            }
        }
        return v;
    };
    vector ans(N, vector<int>(N));
    for (int i = 0; i < N; i++) {
        if (vis[i]) {
            continue;
        }
        auto v = bfs(i, 1);
        for (int x : v) {
            for (int j = 0; j < N; j++) {
                if (a[x][j] != a[v[0]][j]) {
                    return 0;
                }
            }
        }
        for (int j = 1; j < v.size(); j++) {
            ans[i][v[j]] = ans[v[j]][i] = 1;
        }
        vis[i] = 0;
    }
    for (int i = 0; i < N; i++) {
        if (vis[i]) {
            continue;
        }
        auto v = bfs(i, 2);
        if (v.size() == 1) {
            continue;
        }
        if (v.size() == 2) {
            return 0;
        }
        for (int j = 0; j < v.size(); j++) {
            for (int k = j + 1; k < v.size(); k++) {
                if (!a[v[j]][v[k]]) {
                    return 0;
                }
            }
        }
        for (int j = 0; j < v.size(); j++) {
            int x = v[j];
            int y = v[j + 1 == v.size() ? 0 : j + 1];
            ans[x][y] = ans[y][x] = 1;
        }
    }
    build(ans);
    return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:38:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |         for (int j = 1; j < v.size(); j++) {
      |                         ~~^~~~~~~~~~
supertrees.cpp:54:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         for (int j = 0; j < v.size(); j++) {
      |                         ~~^~~~~~~~~~
supertrees.cpp:55:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |             for (int k = j + 1; k < v.size(); k++) {
      |                                 ~~^~~~~~~~~~
supertrees.cpp:61:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |         for (int j = 0; j < v.size(); j++) {
      |                         ~~^~~~~~~~~~
supertrees.cpp:63:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |             int y = v[j + 1 == v.size() ? 0 : j + 1];
      |                       ~~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 292 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 7 ms 1188 KB Output is correct
7 Correct 148 ms 22336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 292 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 7 ms 1188 KB Output is correct
7 Correct 148 ms 22336 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1264 KB Output is correct
13 Correct 157 ms 22372 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 300 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 67 ms 12492 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 44 ms 6088 KB Output is correct
21 Correct 150 ms 22332 KB Output is correct
22 Correct 151 ms 22424 KB Output is correct
23 Correct 156 ms 22348 KB Output is correct
24 Correct 191 ms 22440 KB Output is correct
25 Correct 62 ms 12492 KB Output is correct
26 Correct 59 ms 12416 KB Output is correct
27 Correct 157 ms 22420 KB Output is correct
28 Correct 168 ms 22372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 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 1 ms 212 KB Output is correct
8 Correct 7 ms 1236 KB Output is correct
9 Correct 149 ms 22276 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 160 ms 22208 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 71 ms 12292 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 42 ms 5964 KB Output is correct
22 Correct 168 ms 22296 KB Output is correct
23 Correct 154 ms 22276 KB Output is correct
24 Correct 173 ms 22308 KB Output is correct
25 Correct 63 ms 12276 KB Output is correct
26 Correct 63 ms 12296 KB Output is correct
27 Correct 149 ms 22260 KB Output is correct
28 Correct 162 ms 22272 KB Output is correct
29 Correct 63 ms 12356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 37 ms 6220 KB Output is correct
5 Correct 155 ms 23936 KB Output is correct
6 Correct 152 ms 23884 KB Output is correct
7 Correct 156 ms 23932 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 39 ms 6188 KB Output is correct
10 Correct 151 ms 23900 KB Output is correct
11 Correct 159 ms 23936 KB Output is correct
12 Correct 154 ms 23936 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 38 ms 6252 KB Output is correct
17 Correct 152 ms 23948 KB Output is correct
18 Correct 151 ms 23924 KB Output is correct
19 Correct 150 ms 23940 KB Output is correct
20 Correct 150 ms 23944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 292 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 7 ms 1188 KB Output is correct
7 Correct 148 ms 22336 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1264 KB Output is correct
13 Correct 157 ms 22372 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 300 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 67 ms 12492 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 44 ms 6088 KB Output is correct
21 Correct 150 ms 22332 KB Output is correct
22 Correct 151 ms 22424 KB Output is correct
23 Correct 156 ms 22348 KB Output is correct
24 Correct 191 ms 22440 KB Output is correct
25 Correct 62 ms 12492 KB Output is correct
26 Correct 59 ms 12416 KB Output is correct
27 Correct 157 ms 22420 KB Output is correct
28 Correct 168 ms 22372 KB Output is correct
29 Correct 1 ms 296 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 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 1 ms 212 KB Output is correct
36 Correct 7 ms 1236 KB Output is correct
37 Correct 149 ms 22276 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 7 ms 1236 KB Output is correct
41 Correct 160 ms 22208 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 3 ms 852 KB Output is correct
45 Correct 71 ms 12292 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 42 ms 5964 KB Output is correct
50 Correct 168 ms 22296 KB Output is correct
51 Correct 154 ms 22276 KB Output is correct
52 Correct 173 ms 22308 KB Output is correct
53 Correct 63 ms 12276 KB Output is correct
54 Correct 63 ms 12296 KB Output is correct
55 Correct 149 ms 22260 KB Output is correct
56 Correct 162 ms 22272 KB Output is correct
57 Correct 63 ms 12356 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 3 ms 852 KB Output is correct
61 Correct 70 ms 14064 KB Output is correct
62 Correct 1 ms 212 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 37 ms 6260 KB Output is correct
66 Correct 61 ms 14028 KB Output is correct
67 Correct 60 ms 14080 KB Output is correct
68 Correct 60 ms 14080 KB Output is correct
69 Correct 61 ms 14068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 292 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 7 ms 1188 KB Output is correct
7 Correct 148 ms 22336 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1264 KB Output is correct
13 Correct 157 ms 22372 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 300 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 67 ms 12492 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 44 ms 6088 KB Output is correct
21 Correct 150 ms 22332 KB Output is correct
22 Correct 151 ms 22424 KB Output is correct
23 Correct 156 ms 22348 KB Output is correct
24 Correct 191 ms 22440 KB Output is correct
25 Correct 62 ms 12492 KB Output is correct
26 Correct 59 ms 12416 KB Output is correct
27 Correct 157 ms 22420 KB Output is correct
28 Correct 168 ms 22372 KB Output is correct
29 Correct 1 ms 296 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 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 1 ms 212 KB Output is correct
36 Correct 7 ms 1236 KB Output is correct
37 Correct 149 ms 22276 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 7 ms 1236 KB Output is correct
41 Correct 160 ms 22208 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 3 ms 852 KB Output is correct
45 Correct 71 ms 12292 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 42 ms 5964 KB Output is correct
50 Correct 168 ms 22296 KB Output is correct
51 Correct 154 ms 22276 KB Output is correct
52 Correct 173 ms 22308 KB Output is correct
53 Correct 63 ms 12276 KB Output is correct
54 Correct 63 ms 12296 KB Output is correct
55 Correct 149 ms 22260 KB Output is correct
56 Correct 162 ms 22272 KB Output is correct
57 Correct 63 ms 12356 KB Output is correct
58 Correct 1 ms 296 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 1 ms 300 KB Output is correct
61 Correct 37 ms 6220 KB Output is correct
62 Correct 155 ms 23936 KB Output is correct
63 Correct 152 ms 23884 KB Output is correct
64 Correct 156 ms 23932 KB Output is correct
65 Correct 1 ms 212 KB Output is correct
66 Correct 39 ms 6188 KB Output is correct
67 Correct 151 ms 23900 KB Output is correct
68 Correct 159 ms 23936 KB Output is correct
69 Correct 154 ms 23936 KB Output is correct
70 Correct 1 ms 212 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 1 ms 296 KB Output is correct
73 Correct 38 ms 6252 KB Output is correct
74 Correct 152 ms 23948 KB Output is correct
75 Correct 151 ms 23924 KB Output is correct
76 Correct 150 ms 23940 KB Output is correct
77 Correct 150 ms 23944 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 0 ms 212 KB Output is correct
80 Correct 3 ms 852 KB Output is correct
81 Correct 70 ms 14064 KB Output is correct
82 Correct 1 ms 212 KB Output is correct
83 Correct 1 ms 212 KB Output is correct
84 Correct 1 ms 212 KB Output is correct
85 Correct 37 ms 6260 KB Output is correct
86 Correct 61 ms 14028 KB Output is correct
87 Correct 60 ms 14080 KB Output is correct
88 Correct 60 ms 14080 KB Output is correct
89 Correct 61 ms 14068 KB Output is correct
90 Correct 1 ms 212 KB Output is correct
91 Correct 0 ms 212 KB Output is correct
92 Correct 3 ms 820 KB Output is correct
93 Correct 66 ms 14064 KB Output is correct
94 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
95 Halted 0 ms 0 KB -