Submission #888222

# Submission time Handle Problem Language Result Execution time Memory
888222 2023-12-16T14:14:44 Z 12345678 Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
170 ms 24256 KB
#include "supertrees.h"
#include <bits/stdc++.h>

using namespace std;

const int nx=1e3+5;
bool vs[nx];
vector<int> c[nx], l[nx];

int construct(std::vector<std::vector<int>> p) {
	int n = p.size(), cnt=0;
    for (int i=0; i<n; i++) for (int j=0; j<n; j++) if (p[i][j]==3) return 0;
	vector<vector<int>> answer(n, vector<int> (n, 0));
    vector<int> h;
	for (int i=0; i<n; i++)
    {
        if (vs[i]) continue;
        vector<int> d;
        for (int j=0; j<n; j++) if (p[i][j]==1) vs[j]=1, d.push_back(j);
        for (auto u:d) for (auto v:d) if (p[u][v]!=1) return 0;
        h.push_back(i);
        c[i]=d;
        int sz=d.size();
        for (int j=0; j<sz-1; j++) answer[d[j]][d[j+1]]=answer[d[j+1]][d[j]]=1;
    }
    for (int i=0; i<n; i++) vs[i]=0;
    for (auto i:h)
    {
        if (vs[i]) continue;
        vector<int> d;
        for (auto j:h) if (p[i][j]) d.push_back(j), vs[j]=1;
        for (auto u:d)
        {
            for (auto x:c[u]) l[cnt].push_back(x);
            for (auto v:d)
            {
                if (v==u) continue;
                for (auto x:c[u]) for (auto y:c[v]) if (p[x][y]!=2) return 0;
            }
        }
        cnt++;
        if (d.size()==2) return 0;
        if (d.size()==1) continue;
        int sz=d.size();
        for (int j=0; j<sz-1; j++) answer[d[j]][d[j+1]]=answer[d[j+1]][d[j]]=1;
        answer[d[0]][d[sz-1]]=answer[d[sz-1]][d[0]]=1;
    }
    //cout<<cnt<<'\n';
    for (int i=0; i<cnt; i++)
    {
        for (int j=i+1; j<cnt; j++)
        {
            for (auto x:l[i]) for (auto y:l[j]) if (p[x][y]!=0) return 0;
        }
    }
	build(answer);
	return 1;
}
# 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 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 7 ms 1372 KB Output is correct
7 Correct 161 ms 22140 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 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 7 ms 1372 KB Output is correct
7 Correct 161 ms 22140 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1372 KB Output is correct
13 Correct 158 ms 22088 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 856 KB Output is correct
17 Correct 66 ms 12088 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 52 ms 5832 KB Output is correct
21 Correct 155 ms 22096 KB Output is correct
22 Correct 153 ms 22096 KB Output is correct
23 Correct 159 ms 22076 KB Output is correct
24 Correct 162 ms 22088 KB Output is correct
25 Correct 64 ms 12104 KB Output is correct
26 Correct 69 ms 14124 KB Output is correct
27 Correct 156 ms 24136 KB Output is correct
28 Correct 159 ms 24256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 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 344 KB Output is correct
8 Correct 7 ms 1368 KB Output is correct
9 Correct 157 ms 22184 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 157 ms 22068 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 4 ms 860 KB Output is correct
17 Correct 72 ms 12108 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 39 ms 5980 KB Output is correct
22 Correct 170 ms 22244 KB Output is correct
23 Correct 154 ms 22076 KB Output is correct
24 Correct 159 ms 22088 KB Output is correct
25 Correct 66 ms 12368 KB Output is correct
26 Correct 70 ms 12344 KB Output is correct
27 Correct 155 ms 22100 KB Output is correct
28 Correct 160 ms 22140 KB Output is correct
29 Correct 65 ms 12356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 38 ms 5948 KB Output is correct
5 Correct 154 ms 22084 KB Output is correct
6 Correct 161 ms 22100 KB Output is correct
7 Correct 156 ms 22092 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 39 ms 5940 KB Output is correct
10 Correct 156 ms 22208 KB Output is correct
11 Correct 153 ms 22084 KB Output is correct
12 Correct 161 ms 22088 KB Output is correct
13 Correct 0 ms 600 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 42 ms 5756 KB Output is correct
17 Correct 157 ms 22144 KB Output is correct
18 Correct 156 ms 22100 KB Output is correct
19 Correct 154 ms 22096 KB Output is correct
20 Correct 158 ms 22272 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 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 7 ms 1372 KB Output is correct
7 Correct 161 ms 22140 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1372 KB Output is correct
13 Correct 158 ms 22088 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 856 KB Output is correct
17 Correct 66 ms 12088 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 52 ms 5832 KB Output is correct
21 Correct 155 ms 22096 KB Output is correct
22 Correct 153 ms 22096 KB Output is correct
23 Correct 159 ms 22076 KB Output is correct
24 Correct 162 ms 22088 KB Output is correct
25 Correct 64 ms 12104 KB Output is correct
26 Correct 69 ms 14124 KB Output is correct
27 Correct 156 ms 24136 KB Output is correct
28 Correct 159 ms 24256 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 344 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 344 KB Output is correct
36 Correct 7 ms 1368 KB Output is correct
37 Correct 157 ms 22184 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 7 ms 1372 KB Output is correct
41 Correct 157 ms 22068 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 4 ms 860 KB Output is correct
45 Correct 72 ms 12108 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 39 ms 5980 KB Output is correct
50 Correct 170 ms 22244 KB Output is correct
51 Correct 154 ms 22076 KB Output is correct
52 Correct 159 ms 22088 KB Output is correct
53 Correct 66 ms 12368 KB Output is correct
54 Correct 70 ms 12344 KB Output is correct
55 Correct 155 ms 22100 KB Output is correct
56 Correct 160 ms 22140 KB Output is correct
57 Correct 65 ms 12356 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 860 KB Output is correct
61 Correct 72 ms 14248 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 0 ms 344 KB Output is correct
65 Correct 39 ms 6228 KB Output is correct
66 Correct 67 ms 14252 KB Output is correct
67 Correct 67 ms 14164 KB Output is correct
68 Correct 67 ms 14136 KB Output is correct
69 Correct 65 ms 14140 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 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 7 ms 1372 KB Output is correct
7 Correct 161 ms 22140 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1372 KB Output is correct
13 Correct 158 ms 22088 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 856 KB Output is correct
17 Correct 66 ms 12088 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 52 ms 5832 KB Output is correct
21 Correct 155 ms 22096 KB Output is correct
22 Correct 153 ms 22096 KB Output is correct
23 Correct 159 ms 22076 KB Output is correct
24 Correct 162 ms 22088 KB Output is correct
25 Correct 64 ms 12104 KB Output is correct
26 Correct 69 ms 14124 KB Output is correct
27 Correct 156 ms 24136 KB Output is correct
28 Correct 159 ms 24256 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 344 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 344 KB Output is correct
36 Correct 7 ms 1368 KB Output is correct
37 Correct 157 ms 22184 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 7 ms 1372 KB Output is correct
41 Correct 157 ms 22068 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 4 ms 860 KB Output is correct
45 Correct 72 ms 12108 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 39 ms 5980 KB Output is correct
50 Correct 170 ms 22244 KB Output is correct
51 Correct 154 ms 22076 KB Output is correct
52 Correct 159 ms 22088 KB Output is correct
53 Correct 66 ms 12368 KB Output is correct
54 Correct 70 ms 12344 KB Output is correct
55 Correct 155 ms 22100 KB Output is correct
56 Correct 160 ms 22140 KB Output is correct
57 Correct 65 ms 12356 KB Output is correct
58 Correct 1 ms 344 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 38 ms 5948 KB Output is correct
62 Correct 154 ms 22084 KB Output is correct
63 Correct 161 ms 22100 KB Output is correct
64 Correct 156 ms 22092 KB Output is correct
65 Correct 0 ms 344 KB Output is correct
66 Correct 39 ms 5940 KB Output is correct
67 Correct 156 ms 22208 KB Output is correct
68 Correct 153 ms 22084 KB Output is correct
69 Correct 161 ms 22088 KB Output is correct
70 Correct 0 ms 600 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 42 ms 5756 KB Output is correct
74 Correct 157 ms 22144 KB Output is correct
75 Correct 156 ms 22100 KB Output is correct
76 Correct 154 ms 22096 KB Output is correct
77 Correct 158 ms 22272 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 860 KB Output is correct
81 Correct 72 ms 14248 KB Output is correct
82 Correct 0 ms 348 KB Output is correct
83 Correct 1 ms 348 KB Output is correct
84 Correct 0 ms 344 KB Output is correct
85 Correct 39 ms 6228 KB Output is correct
86 Correct 67 ms 14252 KB Output is correct
87 Correct 67 ms 14164 KB Output is correct
88 Correct 67 ms 14136 KB Output is correct
89 Correct 65 ms 14140 KB Output is correct
90 Correct 1 ms 344 KB Output is correct
91 Correct 0 ms 456 KB Output is correct
92 Correct 3 ms 860 KB Output is correct
93 Correct 67 ms 10148 KB Output is correct
94 Correct 1 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 18 ms 2728 KB Output is correct
98 Correct 64 ms 10284 KB Output is correct
99 Correct 66 ms 10204 KB Output is correct
100 Correct 65 ms 10316 KB Output is correct
101 Correct 64 ms 10296 KB Output is correct
102 Correct 63 ms 10324 KB Output is correct
103 Correct 61 ms 10164 KB Output is correct
104 Correct 69 ms 10168 KB Output is correct
105 Correct 69 ms 10328 KB Output is correct