Submission #728158

# Submission time Handle Problem Language Result Execution time Memory
728158 2023-04-22T03:31:28 Z hoainiem Connecting Supertrees (IOI20_supertrees) C++14
96 / 100
207 ms 24016 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
int n, flag[1008], f[1008];
bool kt[1008];
vector<int>ds, cir, tour, vt[1008];
vector<vector<int> >a;
int construct(std::vector<std::vector<int>> p) {
    n = p.size();
    a.resize(n);
    for (int i = 0; i < n; i++){
        for (int j = i + 1; j < n; j++)
            assert(p[i][j] < 3);
        a[i].resize(n, 0);
    }
    fill(kt, kt + n, false);
    for (int i = 0; i < n; i++)
        if (!kt[i]){
            ds.push_back(i);
            vt[i].push_back(i);
            kt[i] = true;
            flag[i] = i;
            for (int j = i + 1; j < n; j++)
                if (!kt[j] && p[i][j] == 1){
                    vt[i].push_back(j);
                    kt[j] = true;
                    flag[j] = i;
                }
            for (int u : vt[i])
                for (int v : vt[i])
                    if (p[u][v] != 1)
                        return 0;
            for (int pos = 1; pos < (int)vt[i].size(); pos++)
                a[vt[i][pos]][vt[i][pos - 1]] = a[vt[i][pos - 1]][vt[i][pos]] = 1;
        }
    for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++)
            if (p[i][j] == 1 && flag[i] != flag[j])
                return 0;
    fill(kt, kt + n, false);
    for (int i : ds)
        if (!kt[i]){
            cir.clear();
            tour.clear();
            kt[i] = true;
            f[i] = i;
            tour.push_back(i);
            for (int tmp : vt[i])
                cir.push_back(tmp);
            for (int j : ds)
                if (p[i][j] == 2){
                    if (kt[j])
                        return 0;
                    tour.push_back(j);
                    kt[j] = true;
                    f[j] = i;
                    for (int u : vt[j])
                        for (int v : cir)
                            if (p[u][v] != 2)
                                return 0;
                    for (int u : vt[j])
                        cir.push_back(u);
                }
            if (tour.size() <= 2){
                if (tour.size() == 2)
                    return 0;
                else
                    continue;
            }
            tour.push_back(tour[0]);
            for (int pos = 1; pos < (int)tour.size(); pos++)
                a[tour[pos]][tour[pos - 1]] = a[tour[pos - 1]][tour[pos]] = 1;
        }
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            if (p[i][j] == 2 && f[flag[i]] != f[flag[j]])
                return 0;
    build(a);
    return 1;
}
# 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 8 ms 1108 KB Output is correct
7 Correct 163 ms 21964 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 8 ms 1108 KB Output is correct
7 Correct 163 ms 21964 KB Output is correct
8 Correct 1 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 1 ms 212 KB Output is correct
12 Correct 8 ms 1108 KB Output is correct
13 Correct 166 ms 22056 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 5 ms 740 KB Output is correct
17 Correct 81 ms 12080 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 44 ms 5704 KB Output is correct
21 Correct 178 ms 22048 KB Output is correct
22 Correct 163 ms 22092 KB Output is correct
23 Correct 182 ms 22024 KB Output is correct
24 Correct 173 ms 22048 KB Output is correct
25 Correct 76 ms 12076 KB Output is correct
26 Correct 73 ms 12064 KB Output is correct
27 Correct 166 ms 22060 KB Output is correct
28 Correct 181 ms 22064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 9 ms 1236 KB Output is correct
9 Correct 181 ms 22056 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 169 ms 22080 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 5 ms 748 KB Output is correct
17 Correct 74 ms 12196 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 54 ms 5724 KB Output is correct
22 Correct 175 ms 22048 KB Output is correct
23 Correct 165 ms 22072 KB Output is correct
24 Correct 186 ms 22048 KB Output is correct
25 Correct 70 ms 12072 KB Output is correct
26 Correct 76 ms 12204 KB Output is correct
27 Correct 173 ms 23952 KB Output is correct
28 Correct 180 ms 24016 KB Output is correct
29 Correct 74 ms 14148 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 45 ms 5708 KB Output is correct
5 Correct 193 ms 22056 KB Output is correct
6 Correct 207 ms 22048 KB Output is correct
7 Correct 175 ms 22176 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 45 ms 5704 KB Output is correct
10 Correct 168 ms 22056 KB Output is correct
11 Correct 192 ms 22044 KB Output is correct
12 Correct 188 ms 22008 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 43 ms 5796 KB Output is correct
17 Correct 186 ms 22060 KB Output is correct
18 Correct 169 ms 22060 KB Output is correct
19 Correct 183 ms 22012 KB Output is correct
20 Correct 165 ms 22048 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 8 ms 1108 KB Output is correct
7 Correct 163 ms 21964 KB Output is correct
8 Correct 1 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 1 ms 212 KB Output is correct
12 Correct 8 ms 1108 KB Output is correct
13 Correct 166 ms 22056 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 5 ms 740 KB Output is correct
17 Correct 81 ms 12080 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 44 ms 5704 KB Output is correct
21 Correct 178 ms 22048 KB Output is correct
22 Correct 163 ms 22092 KB Output is correct
23 Correct 182 ms 22024 KB Output is correct
24 Correct 173 ms 22048 KB Output is correct
25 Correct 76 ms 12076 KB Output is correct
26 Correct 73 ms 12064 KB Output is correct
27 Correct 166 ms 22060 KB Output is correct
28 Correct 181 ms 22064 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 9 ms 1236 KB Output is correct
37 Correct 181 ms 22056 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 7 ms 1236 KB Output is correct
41 Correct 169 ms 22080 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 5 ms 748 KB Output is correct
45 Correct 74 ms 12196 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 54 ms 5724 KB Output is correct
50 Correct 175 ms 22048 KB Output is correct
51 Correct 165 ms 22072 KB Output is correct
52 Correct 186 ms 22048 KB Output is correct
53 Correct 70 ms 12072 KB Output is correct
54 Correct 76 ms 12204 KB Output is correct
55 Correct 173 ms 23952 KB Output is correct
56 Correct 180 ms 24016 KB Output is correct
57 Correct 74 ms 14148 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 5 ms 852 KB Output is correct
61 Correct 79 ms 14100 KB Output is correct
62 Correct 1 ms 328 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 45 ms 6224 KB Output is correct
66 Correct 73 ms 14148 KB Output is correct
67 Correct 71 ms 14108 KB Output is correct
68 Correct 76 ms 14108 KB Output is correct
69 Correct 75 ms 14104 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 8 ms 1108 KB Output is correct
7 Correct 163 ms 21964 KB Output is correct
8 Correct 1 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 1 ms 212 KB Output is correct
12 Correct 8 ms 1108 KB Output is correct
13 Correct 166 ms 22056 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 5 ms 740 KB Output is correct
17 Correct 81 ms 12080 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 44 ms 5704 KB Output is correct
21 Correct 178 ms 22048 KB Output is correct
22 Correct 163 ms 22092 KB Output is correct
23 Correct 182 ms 22024 KB Output is correct
24 Correct 173 ms 22048 KB Output is correct
25 Correct 76 ms 12076 KB Output is correct
26 Correct 73 ms 12064 KB Output is correct
27 Correct 166 ms 22060 KB Output is correct
28 Correct 181 ms 22064 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 9 ms 1236 KB Output is correct
37 Correct 181 ms 22056 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 7 ms 1236 KB Output is correct
41 Correct 169 ms 22080 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 5 ms 748 KB Output is correct
45 Correct 74 ms 12196 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 54 ms 5724 KB Output is correct
50 Correct 175 ms 22048 KB Output is correct
51 Correct 165 ms 22072 KB Output is correct
52 Correct 186 ms 22048 KB Output is correct
53 Correct 70 ms 12072 KB Output is correct
54 Correct 76 ms 12204 KB Output is correct
55 Correct 173 ms 23952 KB Output is correct
56 Correct 180 ms 24016 KB Output is correct
57 Correct 74 ms 14148 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 45 ms 5708 KB Output is correct
62 Correct 193 ms 22056 KB Output is correct
63 Correct 207 ms 22048 KB Output is correct
64 Correct 175 ms 22176 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 45 ms 5704 KB Output is correct
67 Correct 168 ms 22056 KB Output is correct
68 Correct 192 ms 22044 KB Output is correct
69 Correct 188 ms 22008 KB Output is correct
70 Correct 0 ms 212 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 0 ms 212 KB Output is correct
73 Correct 43 ms 5796 KB Output is correct
74 Correct 186 ms 22060 KB Output is correct
75 Correct 169 ms 22060 KB Output is correct
76 Correct 183 ms 22012 KB Output is correct
77 Correct 165 ms 22048 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 1 ms 340 KB Output is correct
80 Correct 5 ms 852 KB Output is correct
81 Correct 79 ms 14100 KB Output is correct
82 Correct 1 ms 328 KB Output is correct
83 Correct 1 ms 212 KB Output is correct
84 Correct 1 ms 212 KB Output is correct
85 Correct 45 ms 6224 KB Output is correct
86 Correct 73 ms 14148 KB Output is correct
87 Correct 71 ms 14108 KB Output is correct
88 Correct 76 ms 14108 KB Output is correct
89 Correct 75 ms 14104 KB Output is correct
90 Runtime error 1 ms 468 KB Execution killed with signal 6
91 Halted 0 ms 0 KB -