#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
const int nax = 1000;
int par[nax], sz[nax];
vector<int>L[nax];
int find(int v) {
return par[v] = (v == par[v]) ? v : find(par[v]);
}
void unite(int u, int v) {
u = find(u), v = find(v);
if(u==v) return;
if(sz[u] < sz[v]) swap(u, v);
for(int x : L[v]) {
L[u].push_back(x);
}
sz[u] += sz[v];
par[v] = u;
}
int construct(vector<vector<int>> p) {
int n = p.size();
for(int i=0; i<n; ++i) {
par[i] = i, sz[i] = 1;
L[i] = {i};
}
for(int i=0; i<n; ++i) {
for(int j=0; j<n; ++j) if(p[i][j]) {
unite(i, j);
}
}
for(int i=0; i<n; ++i) {
for(int j=0; j<n; ++j) if(!p[i][j]) {
if(find(i) == find(j)) return 0;
}
}
vector<vector<int>>ans(n, vector<int>(n));
for(int i=0; i<n; ++i) if(i==find(i)) {
if(sz[i]>1) {
for(int x=0; x+1<sz[i]; ++x) {
ans[L[i][x]][L[i][x+1]] = ans[L[i][x+1]][L[i][x]] = 1;
}
if(p[i][L[i][1]]==2) {
if(sz[i]<=2) return 0;
for(int x=0; x<sz[i]; ++x) {
for(int y=x+1; y<sz[i]; ++y) {
if(p[L[i][x]][L[i][y]]!=2) {
return 0;
}
}
}
ans[L[i][0]][L[i][sz[i]-1]] = ans[L[i][sz[i]-1]][L[i][0]] = 1;
}
}
}
build(ans);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1188 KB |
Output is correct |
7 |
Correct |
165 ms |
22120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1188 KB |
Output is correct |
7 |
Correct |
165 ms |
22120 KB |
Output is correct |
8 |
Correct |
1 ms |
328 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 |
1232 KB |
Output is correct |
13 |
Correct |
169 ms |
22196 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
87 ms |
8352 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
324 KB |
Output is correct |
20 |
Correct |
41 ms |
5868 KB |
Output is correct |
21 |
Correct |
165 ms |
22124 KB |
Output is correct |
22 |
Correct |
169 ms |
22144 KB |
Output is correct |
23 |
Correct |
172 ms |
22172 KB |
Output is correct |
24 |
Correct |
164 ms |
22172 KB |
Output is correct |
25 |
Correct |
66 ms |
8344 KB |
Output is correct |
26 |
Correct |
66 ms |
8316 KB |
Output is correct |
27 |
Correct |
167 ms |
22188 KB |
Output is correct |
28 |
Correct |
187 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 |
324 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
324 KB |
Output is correct |
8 |
Correct |
7 ms |
1264 KB |
Output is correct |
9 |
Correct |
159 ms |
24048 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
324 KB |
Output is correct |
12 |
Correct |
7 ms |
1240 KB |
Output is correct |
13 |
Correct |
162 ms |
24040 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
77 ms |
10132 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
324 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
41 ms |
6288 KB |
Output is correct |
22 |
Correct |
161 ms |
23952 KB |
Output is correct |
23 |
Correct |
171 ms |
23948 KB |
Output is correct |
24 |
Correct |
167 ms |
23952 KB |
Output is correct |
25 |
Correct |
68 ms |
14040 KB |
Output is correct |
26 |
Correct |
74 ms |
10124 KB |
Output is correct |
27 |
Correct |
162 ms |
24060 KB |
Output is correct |
28 |
Correct |
168 ms |
23964 KB |
Output is correct |
29 |
Correct |
70 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 |
41 ms |
5964 KB |
Output is correct |
5 |
Correct |
161 ms |
22248 KB |
Output is correct |
6 |
Correct |
167 ms |
22156 KB |
Output is correct |
7 |
Correct |
169 ms |
22224 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
42 ms |
5836 KB |
Output is correct |
10 |
Correct |
169 ms |
22132 KB |
Output is correct |
11 |
Correct |
165 ms |
22176 KB |
Output is correct |
12 |
Correct |
173 ms |
22176 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Incorrect |
0 ms |
340 KB |
Answer gives possible 0 while actual possible 1 |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1188 KB |
Output is correct |
7 |
Correct |
165 ms |
22120 KB |
Output is correct |
8 |
Correct |
1 ms |
328 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 |
1232 KB |
Output is correct |
13 |
Correct |
169 ms |
22196 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
87 ms |
8352 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
324 KB |
Output is correct |
20 |
Correct |
41 ms |
5868 KB |
Output is correct |
21 |
Correct |
165 ms |
22124 KB |
Output is correct |
22 |
Correct |
169 ms |
22144 KB |
Output is correct |
23 |
Correct |
172 ms |
22172 KB |
Output is correct |
24 |
Correct |
164 ms |
22172 KB |
Output is correct |
25 |
Correct |
66 ms |
8344 KB |
Output is correct |
26 |
Correct |
66 ms |
8316 KB |
Output is correct |
27 |
Correct |
167 ms |
22188 KB |
Output is correct |
28 |
Correct |
187 ms |
22220 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
324 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
324 KB |
Output is correct |
36 |
Correct |
7 ms |
1264 KB |
Output is correct |
37 |
Correct |
159 ms |
24048 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
324 KB |
Output is correct |
40 |
Correct |
7 ms |
1240 KB |
Output is correct |
41 |
Correct |
162 ms |
24040 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
4 ms |
724 KB |
Output is correct |
45 |
Correct |
77 ms |
10132 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
324 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
41 ms |
6288 KB |
Output is correct |
50 |
Correct |
161 ms |
23952 KB |
Output is correct |
51 |
Correct |
171 ms |
23948 KB |
Output is correct |
52 |
Correct |
167 ms |
23952 KB |
Output is correct |
53 |
Correct |
68 ms |
14040 KB |
Output is correct |
54 |
Correct |
74 ms |
10124 KB |
Output is correct |
55 |
Correct |
162 ms |
24060 KB |
Output is correct |
56 |
Correct |
168 ms |
23964 KB |
Output is correct |
57 |
Correct |
70 ms |
14148 KB |
Output is correct |
58 |
Correct |
0 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
212 KB |
Output is correct |
60 |
Correct |
3 ms |
724 KB |
Output is correct |
61 |
Correct |
75 ms |
10140 KB |
Output is correct |
62 |
Correct |
0 ms |
212 KB |
Output is correct |
63 |
Correct |
1 ms |
340 KB |
Output is correct |
64 |
Correct |
1 ms |
324 KB |
Output is correct |
65 |
Incorrect |
18 ms |
3728 KB |
Answer gives possible 0 while actual possible 1 |
66 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1188 KB |
Output is correct |
7 |
Correct |
165 ms |
22120 KB |
Output is correct |
8 |
Correct |
1 ms |
328 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 |
1232 KB |
Output is correct |
13 |
Correct |
169 ms |
22196 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
87 ms |
8352 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
324 KB |
Output is correct |
20 |
Correct |
41 ms |
5868 KB |
Output is correct |
21 |
Correct |
165 ms |
22124 KB |
Output is correct |
22 |
Correct |
169 ms |
22144 KB |
Output is correct |
23 |
Correct |
172 ms |
22172 KB |
Output is correct |
24 |
Correct |
164 ms |
22172 KB |
Output is correct |
25 |
Correct |
66 ms |
8344 KB |
Output is correct |
26 |
Correct |
66 ms |
8316 KB |
Output is correct |
27 |
Correct |
167 ms |
22188 KB |
Output is correct |
28 |
Correct |
187 ms |
22220 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
324 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
324 KB |
Output is correct |
36 |
Correct |
7 ms |
1264 KB |
Output is correct |
37 |
Correct |
159 ms |
24048 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
324 KB |
Output is correct |
40 |
Correct |
7 ms |
1240 KB |
Output is correct |
41 |
Correct |
162 ms |
24040 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
4 ms |
724 KB |
Output is correct |
45 |
Correct |
77 ms |
10132 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
324 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
41 ms |
6288 KB |
Output is correct |
50 |
Correct |
161 ms |
23952 KB |
Output is correct |
51 |
Correct |
171 ms |
23948 KB |
Output is correct |
52 |
Correct |
167 ms |
23952 KB |
Output is correct |
53 |
Correct |
68 ms |
14040 KB |
Output is correct |
54 |
Correct |
74 ms |
10124 KB |
Output is correct |
55 |
Correct |
162 ms |
24060 KB |
Output is correct |
56 |
Correct |
168 ms |
23964 KB |
Output is correct |
57 |
Correct |
70 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 |
41 ms |
5964 KB |
Output is correct |
62 |
Correct |
161 ms |
22248 KB |
Output is correct |
63 |
Correct |
167 ms |
22156 KB |
Output is correct |
64 |
Correct |
169 ms |
22224 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
42 ms |
5836 KB |
Output is correct |
67 |
Correct |
169 ms |
22132 KB |
Output is correct |
68 |
Correct |
165 ms |
22176 KB |
Output is correct |
69 |
Correct |
173 ms |
22176 KB |
Output is correct |
70 |
Correct |
1 ms |
340 KB |
Output is correct |
71 |
Correct |
0 ms |
212 KB |
Output is correct |
72 |
Incorrect |
0 ms |
340 KB |
Answer gives possible 0 while actual possible 1 |
73 |
Halted |
0 ms |
0 KB |
- |