#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int Nmax=1010;
int N, A[Nmax][Nmax];
int G[Nmax], cnt, P[Nmax], dist[Nmax];
bool ans[Nmax][Nmax], chk[Nmax];
vector<int> nodes, V[Nmax], adj[Nmax], adj2[Nmax];
int Find(int x) {return G[x]?G[x]=Find(G[x]):x;}
void Union(int x, int y) {
x=Find(x), y=Find(y);
if(x==y) return;
G[x]=y;
}
void DFS(int curr) {
nodes.push_back(curr);
for(int next:adj[curr]) if(!P[next]) {
ans[curr][next]=ans[next][curr]=1;
P[next]=cnt;
DFS(next);
}
}
void DFS2(int curr) {
for(int next:adj[curr]) if(!chk[next]) {
chk[next]=1;
dist[next]++;
DFS2(next);
chk[next]=0;
}
}
int construct(vector<vector<int>> p) {
N=p.size();
for(int i=1; i<=N; i++) for(int j=1; j<=N; j++) {
A[i][j]=p[i-1][j-1];
if(A[i][j]==3) {cerr<<0; return 0;}
}
for(int i=1; i<=N; i++) {
for(int j=1; j<i; j++) if(A[i][j]) Union(i, j);
}
for(int i=1; i<=N; i++) {
for(int j=1; j<i; j++) if(!A[i][j] && Find(i)==Find(j)) return 0;
}
for(int i=1; i<=N; i++) V[Find(i)].push_back(i);
for(int i=1; i<=N; i++) {
if(V[i].empty()) continue;
for(int j:V[i]) for(int k:V[i]) if(j!=k && A[j][k]==1) {
adj[j].push_back(k);
}
vector<int> tmp;
for(int j:V[i]) if(!P[j]) {
nodes.clear();
P[j]=++cnt;
DFS(j);
for(int k:nodes) for(int l:nodes) if(A[k][l]==2) return 0;
tmp.push_back(j);
}
if(tmp.size()==2) return 0;
for(int j=0; j<(int)tmp.size()-1; j++) ans[tmp[j]][tmp[j+1]]=ans[tmp[j+1]][tmp[j]]=1;
if(tmp.size()>1) ans[tmp.back()][tmp[0]]=ans[tmp[0]][tmp.back()]=1;
}
vector<vector<int>> tmp;
tmp.resize(N);
for(int i=1; i<=N; i++) for(int j=1; j<=N; j++) tmp[i-1].push_back(ans[i][j]);
build(tmp);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
372 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
11 ms |
2552 KB |
Output is correct |
7 |
Correct |
173 ms |
33144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
372 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
11 ms |
2552 KB |
Output is correct |
7 |
Correct |
173 ms |
33144 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
368 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
8 ms |
2168 KB |
Output is correct |
13 |
Correct |
168 ms |
28056 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
4 ms |
1540 KB |
Output is correct |
17 |
Correct |
75 ms |
14140 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
45 ms |
8772 KB |
Output is correct |
21 |
Correct |
176 ms |
29696 KB |
Output is correct |
22 |
Correct |
170 ms |
29112 KB |
Output is correct |
23 |
Correct |
182 ms |
31176 KB |
Output is correct |
24 |
Correct |
164 ms |
28356 KB |
Output is correct |
25 |
Correct |
74 ms |
14140 KB |
Output is correct |
26 |
Correct |
72 ms |
14136 KB |
Output is correct |
27 |
Correct |
182 ms |
32160 KB |
Output is correct |
28 |
Correct |
167 ms |
28352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
11 ms |
2140 KB |
Output is correct |
9 |
Correct |
173 ms |
28100 KB |
Output is correct |
10 |
Correct |
1 ms |
372 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
8 ms |
2380 KB |
Output is correct |
13 |
Correct |
168 ms |
29048 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
4 ms |
1508 KB |
Output is correct |
17 |
Correct |
82 ms |
14136 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
21 |
Correct |
43 ms |
8752 KB |
Output is correct |
22 |
Correct |
168 ms |
29048 KB |
Output is correct |
23 |
Correct |
171 ms |
29044 KB |
Output is correct |
24 |
Correct |
190 ms |
29048 KB |
Output is correct |
25 |
Correct |
73 ms |
14276 KB |
Output is correct |
26 |
Correct |
76 ms |
14072 KB |
Output is correct |
27 |
Correct |
197 ms |
29048 KB |
Output is correct |
28 |
Correct |
186 ms |
29036 KB |
Output is correct |
29 |
Correct |
64 ms |
14272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
368 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
45 ms |
8880 KB |
Output is correct |
5 |
Correct |
169 ms |
29644 KB |
Output is correct |
6 |
Correct |
163 ms |
29144 KB |
Output is correct |
7 |
Correct |
193 ms |
31172 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
56 ms |
8768 KB |
Output is correct |
10 |
Correct |
166 ms |
29124 KB |
Output is correct |
11 |
Correct |
169 ms |
29144 KB |
Output is correct |
12 |
Correct |
176 ms |
29112 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
43 ms |
8808 KB |
Output is correct |
17 |
Correct |
191 ms |
29024 KB |
Output is correct |
18 |
Correct |
174 ms |
29112 KB |
Output is correct |
19 |
Correct |
168 ms |
29256 KB |
Output is correct |
20 |
Correct |
168 ms |
28316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
372 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
11 ms |
2552 KB |
Output is correct |
7 |
Correct |
173 ms |
33144 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
368 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
8 ms |
2168 KB |
Output is correct |
13 |
Correct |
168 ms |
28056 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
4 ms |
1540 KB |
Output is correct |
17 |
Correct |
75 ms |
14140 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
45 ms |
8772 KB |
Output is correct |
21 |
Correct |
176 ms |
29696 KB |
Output is correct |
22 |
Correct |
170 ms |
29112 KB |
Output is correct |
23 |
Correct |
182 ms |
31176 KB |
Output is correct |
24 |
Correct |
164 ms |
28356 KB |
Output is correct |
25 |
Correct |
74 ms |
14140 KB |
Output is correct |
26 |
Correct |
72 ms |
14136 KB |
Output is correct |
27 |
Correct |
182 ms |
32160 KB |
Output is correct |
28 |
Correct |
167 ms |
28352 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
0 ms |
364 KB |
Output is correct |
33 |
Correct |
0 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
11 ms |
2140 KB |
Output is correct |
37 |
Correct |
173 ms |
28100 KB |
Output is correct |
38 |
Correct |
1 ms |
372 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
8 ms |
2380 KB |
Output is correct |
41 |
Correct |
168 ms |
29048 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
4 ms |
1508 KB |
Output is correct |
45 |
Correct |
82 ms |
14136 KB |
Output is correct |
46 |
Correct |
1 ms |
332 KB |
Output is correct |
47 |
Correct |
1 ms |
332 KB |
Output is correct |
48 |
Correct |
0 ms |
332 KB |
Output is correct |
49 |
Correct |
43 ms |
8752 KB |
Output is correct |
50 |
Correct |
168 ms |
29048 KB |
Output is correct |
51 |
Correct |
171 ms |
29044 KB |
Output is correct |
52 |
Correct |
190 ms |
29048 KB |
Output is correct |
53 |
Correct |
73 ms |
14276 KB |
Output is correct |
54 |
Correct |
76 ms |
14072 KB |
Output is correct |
55 |
Correct |
197 ms |
29048 KB |
Output is correct |
56 |
Correct |
186 ms |
29036 KB |
Output is correct |
57 |
Correct |
64 ms |
14272 KB |
Output is correct |
58 |
Correct |
1 ms |
332 KB |
Output is correct |
59 |
Correct |
1 ms |
332 KB |
Output is correct |
60 |
Correct |
4 ms |
1484 KB |
Output is correct |
61 |
Correct |
74 ms |
14156 KB |
Output is correct |
62 |
Correct |
1 ms |
332 KB |
Output is correct |
63 |
Correct |
1 ms |
332 KB |
Output is correct |
64 |
Correct |
0 ms |
332 KB |
Output is correct |
65 |
Correct |
43 ms |
8752 KB |
Output is correct |
66 |
Correct |
65 ms |
14144 KB |
Output is correct |
67 |
Correct |
66 ms |
14140 KB |
Output is correct |
68 |
Correct |
69 ms |
14152 KB |
Output is correct |
69 |
Correct |
71 ms |
14148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
372 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
11 ms |
2552 KB |
Output is correct |
7 |
Correct |
173 ms |
33144 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
368 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
8 ms |
2168 KB |
Output is correct |
13 |
Correct |
168 ms |
28056 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
4 ms |
1540 KB |
Output is correct |
17 |
Correct |
75 ms |
14140 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
45 ms |
8772 KB |
Output is correct |
21 |
Correct |
176 ms |
29696 KB |
Output is correct |
22 |
Correct |
170 ms |
29112 KB |
Output is correct |
23 |
Correct |
182 ms |
31176 KB |
Output is correct |
24 |
Correct |
164 ms |
28356 KB |
Output is correct |
25 |
Correct |
74 ms |
14140 KB |
Output is correct |
26 |
Correct |
72 ms |
14136 KB |
Output is correct |
27 |
Correct |
182 ms |
32160 KB |
Output is correct |
28 |
Correct |
167 ms |
28352 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
0 ms |
364 KB |
Output is correct |
33 |
Correct |
0 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
11 ms |
2140 KB |
Output is correct |
37 |
Correct |
173 ms |
28100 KB |
Output is correct |
38 |
Correct |
1 ms |
372 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
8 ms |
2380 KB |
Output is correct |
41 |
Correct |
168 ms |
29048 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
4 ms |
1508 KB |
Output is correct |
45 |
Correct |
82 ms |
14136 KB |
Output is correct |
46 |
Correct |
1 ms |
332 KB |
Output is correct |
47 |
Correct |
1 ms |
332 KB |
Output is correct |
48 |
Correct |
0 ms |
332 KB |
Output is correct |
49 |
Correct |
43 ms |
8752 KB |
Output is correct |
50 |
Correct |
168 ms |
29048 KB |
Output is correct |
51 |
Correct |
171 ms |
29044 KB |
Output is correct |
52 |
Correct |
190 ms |
29048 KB |
Output is correct |
53 |
Correct |
73 ms |
14276 KB |
Output is correct |
54 |
Correct |
76 ms |
14072 KB |
Output is correct |
55 |
Correct |
197 ms |
29048 KB |
Output is correct |
56 |
Correct |
186 ms |
29036 KB |
Output is correct |
57 |
Correct |
64 ms |
14272 KB |
Output is correct |
58 |
Correct |
0 ms |
332 KB |
Output is correct |
59 |
Correct |
0 ms |
368 KB |
Output is correct |
60 |
Correct |
1 ms |
332 KB |
Output is correct |
61 |
Correct |
45 ms |
8880 KB |
Output is correct |
62 |
Correct |
169 ms |
29644 KB |
Output is correct |
63 |
Correct |
163 ms |
29144 KB |
Output is correct |
64 |
Correct |
193 ms |
31172 KB |
Output is correct |
65 |
Correct |
1 ms |
332 KB |
Output is correct |
66 |
Correct |
56 ms |
8768 KB |
Output is correct |
67 |
Correct |
166 ms |
29124 KB |
Output is correct |
68 |
Correct |
169 ms |
29144 KB |
Output is correct |
69 |
Correct |
176 ms |
29112 KB |
Output is correct |
70 |
Correct |
0 ms |
332 KB |
Output is correct |
71 |
Correct |
1 ms |
332 KB |
Output is correct |
72 |
Correct |
1 ms |
332 KB |
Output is correct |
73 |
Correct |
43 ms |
8808 KB |
Output is correct |
74 |
Correct |
191 ms |
29024 KB |
Output is correct |
75 |
Correct |
174 ms |
29112 KB |
Output is correct |
76 |
Correct |
168 ms |
29256 KB |
Output is correct |
77 |
Correct |
168 ms |
28316 KB |
Output is correct |
78 |
Correct |
1 ms |
332 KB |
Output is correct |
79 |
Correct |
1 ms |
332 KB |
Output is correct |
80 |
Correct |
4 ms |
1484 KB |
Output is correct |
81 |
Correct |
74 ms |
14156 KB |
Output is correct |
82 |
Correct |
1 ms |
332 KB |
Output is correct |
83 |
Correct |
1 ms |
332 KB |
Output is correct |
84 |
Correct |
0 ms |
332 KB |
Output is correct |
85 |
Correct |
43 ms |
8752 KB |
Output is correct |
86 |
Correct |
65 ms |
14144 KB |
Output is correct |
87 |
Correct |
66 ms |
14140 KB |
Output is correct |
88 |
Correct |
69 ms |
14152 KB |
Output is correct |
89 |
Correct |
71 ms |
14148 KB |
Output is correct |
90 |
Correct |
1 ms |
332 KB |
Output is correct |
91 |
Correct |
1 ms |
372 KB |
Output is correct |
92 |
Correct |
4 ms |
764 KB |
Output is correct |
93 |
Correct |
72 ms |
10176 KB |
Output is correct |
94 |
Correct |
1 ms |
376 KB |
Output is correct |
95 |
Correct |
1 ms |
372 KB |
Output is correct |
96 |
Correct |
0 ms |
332 KB |
Output is correct |
97 |
Correct |
16 ms |
2876 KB |
Output is correct |
98 |
Correct |
63 ms |
10432 KB |
Output is correct |
99 |
Correct |
70 ms |
10692 KB |
Output is correct |
100 |
Correct |
61 ms |
10436 KB |
Output is correct |
101 |
Correct |
68 ms |
11460 KB |
Output is correct |
102 |
Correct |
61 ms |
10172 KB |
Output is correct |
103 |
Correct |
63 ms |
10176 KB |
Output is correct |
104 |
Correct |
61 ms |
10176 KB |
Output is correct |
105 |
Correct |
69 ms |
10176 KB |
Output is correct |