#include "supertrees.h"
#include<iostream>
#include <vector>
using namespace std;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define forsn(i, s, n) for(int i=s; i<(int)n; ++i)
#define PB push_back
const int MAXN = 1010;
int n;
bool vi1[MAXN], vi2[MAXN], ad1[MAXN][MAXN], ad2[MAXN][MAXN];
vector<int> comp;
void dfs(int v, bool* vis, bool adj[][MAXN]){
vis[v]=true;
comp.PB(v);
forn(i, n) if(!vis[i] && adj[v][i]) dfs(i, vis, adj);
}
bool check(vector<int>& com, bool adj[][MAXN]){
bool ret = true;
int sz = (int)com.size();
forn(i, sz) forsn(j, i+1, sz) ret &= adj[com[i]][com[j]];
return ret;
}
int construct(std::vector<std::vector<int>> p) {
n = (int)p.size();
std::vector<std::vector<int>> ans(n, vector<int>(n, 0));
bool has3 = false;
forn(i, n) forn(j, n) has3 |= (ans[i][j] == 3);
if(has3) return 0;
forn(i, n) forn(j, n) ad1[i][j] = (p[i][j] > 0);
forn(i, n) forn(j, n) ad2[i][j] = (p[i][j] == 1);
forn(i, n) if(!vi1[i]){
dfs(i, vi1, ad1);
if(!check(comp, ad1)) return 0;
vector<int> al, rep;
swap(comp, al);
for(int el:al) if(!vi2[el]){
dfs(el, vi2, ad2);
if(!check(comp, ad2)) return 0;
forn(j, comp.size() - 1) ans[comp[j]][comp[j+1]]=ans[comp[j+1]][comp[j]]=1;
rep.PB(comp.back());
comp.clear();
}
if((int)rep.size() == 2) return 0;
if((int)rep.size() > 2){
forn(j, rep.size() - 1) ans[rep[j]][rep[j+1]]=ans[rep[j+1]][rep[j]]=1;
ans[rep.front()][rep.back()]=ans[rep.back()][rep.front()]=1;
}
}
build(ans);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
236 KB |
Output is correct |
2 |
Correct |
0 ms |
312 KB |
Output is correct |
3 |
Correct |
1 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 |
1600 KB |
Output is correct |
7 |
Correct |
155 ms |
25976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
236 KB |
Output is correct |
2 |
Correct |
0 ms |
312 KB |
Output is correct |
3 |
Correct |
1 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 |
1600 KB |
Output is correct |
7 |
Correct |
155 ms |
25976 KB |
Output is correct |
8 |
Correct |
1 ms |
236 KB |
Output is correct |
9 |
Correct |
1 ms |
312 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
10 ms |
1640 KB |
Output is correct |
13 |
Correct |
153 ms |
25928 KB |
Output is correct |
14 |
Correct |
1 ms |
312 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
1236 KB |
Output is correct |
17 |
Correct |
80 ms |
16008 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
312 KB |
Output is correct |
20 |
Correct |
39 ms |
7244 KB |
Output is correct |
21 |
Correct |
170 ms |
25948 KB |
Output is correct |
22 |
Correct |
155 ms |
25916 KB |
Output is correct |
23 |
Correct |
161 ms |
25960 KB |
Output is correct |
24 |
Correct |
171 ms |
25984 KB |
Output is correct |
25 |
Correct |
78 ms |
16016 KB |
Output is correct |
26 |
Correct |
64 ms |
16016 KB |
Output is correct |
27 |
Correct |
189 ms |
26008 KB |
Output is correct |
28 |
Correct |
179 ms |
25936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
8 ms |
1620 KB |
Output is correct |
9 |
Correct |
154 ms |
25868 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
1608 KB |
Output is correct |
13 |
Correct |
215 ms |
25996 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
1236 KB |
Output is correct |
17 |
Correct |
79 ms |
16132 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
308 KB |
Output is correct |
21 |
Correct |
59 ms |
7204 KB |
Output is correct |
22 |
Correct |
186 ms |
25888 KB |
Output is correct |
23 |
Correct |
207 ms |
25964 KB |
Output is correct |
24 |
Correct |
189 ms |
25976 KB |
Output is correct |
25 |
Correct |
81 ms |
16076 KB |
Output is correct |
26 |
Correct |
63 ms |
15996 KB |
Output is correct |
27 |
Correct |
186 ms |
25972 KB |
Output is correct |
28 |
Correct |
186 ms |
25984 KB |
Output is correct |
29 |
Correct |
65 ms |
16048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
40 ms |
7180 KB |
Output is correct |
5 |
Correct |
217 ms |
25948 KB |
Output is correct |
6 |
Correct |
172 ms |
25964 KB |
Output is correct |
7 |
Correct |
192 ms |
26004 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
49 ms |
7208 KB |
Output is correct |
10 |
Correct |
183 ms |
25948 KB |
Output is correct |
11 |
Correct |
175 ms |
25908 KB |
Output is correct |
12 |
Correct |
182 ms |
25988 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
264 KB |
Output is correct |
16 |
Correct |
44 ms |
7212 KB |
Output is correct |
17 |
Correct |
181 ms |
25992 KB |
Output is correct |
18 |
Correct |
196 ms |
25944 KB |
Output is correct |
19 |
Correct |
160 ms |
25880 KB |
Output is correct |
20 |
Correct |
162 ms |
25880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
236 KB |
Output is correct |
2 |
Correct |
0 ms |
312 KB |
Output is correct |
3 |
Correct |
1 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 |
1600 KB |
Output is correct |
7 |
Correct |
155 ms |
25976 KB |
Output is correct |
8 |
Correct |
1 ms |
236 KB |
Output is correct |
9 |
Correct |
1 ms |
312 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
10 ms |
1640 KB |
Output is correct |
13 |
Correct |
153 ms |
25928 KB |
Output is correct |
14 |
Correct |
1 ms |
312 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
1236 KB |
Output is correct |
17 |
Correct |
80 ms |
16008 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
312 KB |
Output is correct |
20 |
Correct |
39 ms |
7244 KB |
Output is correct |
21 |
Correct |
170 ms |
25948 KB |
Output is correct |
22 |
Correct |
155 ms |
25916 KB |
Output is correct |
23 |
Correct |
161 ms |
25960 KB |
Output is correct |
24 |
Correct |
171 ms |
25984 KB |
Output is correct |
25 |
Correct |
78 ms |
16016 KB |
Output is correct |
26 |
Correct |
64 ms |
16016 KB |
Output is correct |
27 |
Correct |
189 ms |
26008 KB |
Output is correct |
28 |
Correct |
179 ms |
25936 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
312 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
316 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
8 ms |
1620 KB |
Output is correct |
37 |
Correct |
154 ms |
25868 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
8 ms |
1608 KB |
Output is correct |
41 |
Correct |
215 ms |
25996 KB |
Output is correct |
42 |
Correct |
1 ms |
256 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
3 ms |
1236 KB |
Output is correct |
45 |
Correct |
79 ms |
16132 KB |
Output is correct |
46 |
Correct |
1 ms |
256 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
308 KB |
Output is correct |
49 |
Correct |
59 ms |
7204 KB |
Output is correct |
50 |
Correct |
186 ms |
25888 KB |
Output is correct |
51 |
Correct |
207 ms |
25964 KB |
Output is correct |
52 |
Correct |
189 ms |
25976 KB |
Output is correct |
53 |
Correct |
81 ms |
16076 KB |
Output is correct |
54 |
Correct |
63 ms |
15996 KB |
Output is correct |
55 |
Correct |
186 ms |
25972 KB |
Output is correct |
56 |
Correct |
186 ms |
25984 KB |
Output is correct |
57 |
Correct |
65 ms |
16048 KB |
Output is correct |
58 |
Correct |
1 ms |
308 KB |
Output is correct |
59 |
Correct |
1 ms |
212 KB |
Output is correct |
60 |
Correct |
3 ms |
1236 KB |
Output is correct |
61 |
Correct |
76 ms |
16108 KB |
Output is correct |
62 |
Correct |
1 ms |
340 KB |
Output is correct |
63 |
Correct |
1 ms |
212 KB |
Output is correct |
64 |
Correct |
1 ms |
212 KB |
Output is correct |
65 |
Correct |
52 ms |
7168 KB |
Output is correct |
66 |
Correct |
68 ms |
16000 KB |
Output is correct |
67 |
Correct |
82 ms |
16008 KB |
Output is correct |
68 |
Correct |
80 ms |
16000 KB |
Output is correct |
69 |
Correct |
67 ms |
15996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
236 KB |
Output is correct |
2 |
Correct |
0 ms |
312 KB |
Output is correct |
3 |
Correct |
1 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 |
1600 KB |
Output is correct |
7 |
Correct |
155 ms |
25976 KB |
Output is correct |
8 |
Correct |
1 ms |
236 KB |
Output is correct |
9 |
Correct |
1 ms |
312 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
10 ms |
1640 KB |
Output is correct |
13 |
Correct |
153 ms |
25928 KB |
Output is correct |
14 |
Correct |
1 ms |
312 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
1236 KB |
Output is correct |
17 |
Correct |
80 ms |
16008 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
312 KB |
Output is correct |
20 |
Correct |
39 ms |
7244 KB |
Output is correct |
21 |
Correct |
170 ms |
25948 KB |
Output is correct |
22 |
Correct |
155 ms |
25916 KB |
Output is correct |
23 |
Correct |
161 ms |
25960 KB |
Output is correct |
24 |
Correct |
171 ms |
25984 KB |
Output is correct |
25 |
Correct |
78 ms |
16016 KB |
Output is correct |
26 |
Correct |
64 ms |
16016 KB |
Output is correct |
27 |
Correct |
189 ms |
26008 KB |
Output is correct |
28 |
Correct |
179 ms |
25936 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
312 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
316 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
8 ms |
1620 KB |
Output is correct |
37 |
Correct |
154 ms |
25868 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
8 ms |
1608 KB |
Output is correct |
41 |
Correct |
215 ms |
25996 KB |
Output is correct |
42 |
Correct |
1 ms |
256 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
3 ms |
1236 KB |
Output is correct |
45 |
Correct |
79 ms |
16132 KB |
Output is correct |
46 |
Correct |
1 ms |
256 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
308 KB |
Output is correct |
49 |
Correct |
59 ms |
7204 KB |
Output is correct |
50 |
Correct |
186 ms |
25888 KB |
Output is correct |
51 |
Correct |
207 ms |
25964 KB |
Output is correct |
52 |
Correct |
189 ms |
25976 KB |
Output is correct |
53 |
Correct |
81 ms |
16076 KB |
Output is correct |
54 |
Correct |
63 ms |
15996 KB |
Output is correct |
55 |
Correct |
186 ms |
25972 KB |
Output is correct |
56 |
Correct |
186 ms |
25984 KB |
Output is correct |
57 |
Correct |
65 ms |
16048 KB |
Output is correct |
58 |
Correct |
1 ms |
340 KB |
Output is correct |
59 |
Correct |
1 ms |
308 KB |
Output is correct |
60 |
Correct |
1 ms |
312 KB |
Output is correct |
61 |
Correct |
40 ms |
7180 KB |
Output is correct |
62 |
Correct |
217 ms |
25948 KB |
Output is correct |
63 |
Correct |
172 ms |
25964 KB |
Output is correct |
64 |
Correct |
192 ms |
26004 KB |
Output is correct |
65 |
Correct |
1 ms |
212 KB |
Output is correct |
66 |
Correct |
49 ms |
7208 KB |
Output is correct |
67 |
Correct |
183 ms |
25948 KB |
Output is correct |
68 |
Correct |
175 ms |
25908 KB |
Output is correct |
69 |
Correct |
182 ms |
25988 KB |
Output is correct |
70 |
Correct |
1 ms |
212 KB |
Output is correct |
71 |
Correct |
1 ms |
212 KB |
Output is correct |
72 |
Correct |
1 ms |
264 KB |
Output is correct |
73 |
Correct |
44 ms |
7212 KB |
Output is correct |
74 |
Correct |
181 ms |
25992 KB |
Output is correct |
75 |
Correct |
196 ms |
25944 KB |
Output is correct |
76 |
Correct |
160 ms |
25880 KB |
Output is correct |
77 |
Correct |
162 ms |
25880 KB |
Output is correct |
78 |
Correct |
1 ms |
308 KB |
Output is correct |
79 |
Correct |
1 ms |
212 KB |
Output is correct |
80 |
Correct |
3 ms |
1236 KB |
Output is correct |
81 |
Correct |
76 ms |
16108 KB |
Output is correct |
82 |
Correct |
1 ms |
340 KB |
Output is correct |
83 |
Correct |
1 ms |
212 KB |
Output is correct |
84 |
Correct |
1 ms |
212 KB |
Output is correct |
85 |
Correct |
52 ms |
7168 KB |
Output is correct |
86 |
Correct |
68 ms |
16000 KB |
Output is correct |
87 |
Correct |
82 ms |
16008 KB |
Output is correct |
88 |
Correct |
80 ms |
16000 KB |
Output is correct |
89 |
Correct |
67 ms |
15996 KB |
Output is correct |
90 |
Correct |
1 ms |
320 KB |
Output is correct |
91 |
Correct |
1 ms |
212 KB |
Output is correct |
92 |
Correct |
5 ms |
1236 KB |
Output is correct |
93 |
Correct |
88 ms |
16124 KB |
Output is correct |
94 |
Incorrect |
1 ms |
212 KB |
Answer gives possible 1 while actual possible 0 |
95 |
Halted |
0 ms |
0 KB |
- |