#include<bits/stdc++.h>
#include "supertrees.h"
using namespace std;
#define all(v) v.begin(), v.end()
typedef long long ll;
const int NMAX = 1005;
int par[NMAX], vis[NMAX], p[NMAX][NMAX], a, b;
vector<int> C[NMAX], V, t;
int find(int x){return par[x] == -1 ? x : par[x] = find(par[x]);}
void dfs(int x){
if(vis[x]) return;
vis[x] = 1;
t.emplace_back(x);
for(int& y : V) if(!vis[y] && p[x][y] == 2) dfs(y);
return;
}
int construct(vector<vector<int>>p_){
int n = p_.size(), a, b;
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++) p[i][j] = p_[i][j];
vector<vector<int>> E(n, vector<int>(n, 0));
memset(par, -1, sizeof(par));
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++){
if(p[i][j] == 3) return 0;
a = find(i); b = find(j);
if(a == b) continue;
if(p[i][j] == 1){
par[b] = a; E[i][j] = E[j][i] = 1;
}
}
for(int i = 0; i < n; i++) C[find(i)].emplace_back(i);
for(int i = 0; i < n; i++)
if(find(i) == i){
V.emplace_back(i);
for(int&x : C[i])
for(int j = 0; j < n; j++)
if(p[x][j] != p[i][j]) return 0;
}
for(int& x : V)
if(!vis[x]){
t.clear();
dfs(x);
int sz = t.size();
if(sz == 1) continue;
if(sz == 2) return 0;
for(int i = 0; i < sz; i++){
a = t[i], b = t[(i + 1) % sz];
E[a][b] = E[b][a] = 1;
for(int j = 0; j < sz; j++)
if(i != j && p[t[i]][t[j]] != 2) return 0;
}
}
build(E);
return 1;
}
/*
int main(void){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n;
cin >> n;
vector<vector<int>> v (n, vector<int>(n, 0));
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++) cin >> v[i][j];
cout << construct(v) << '\n';
return 0;
}
*/
/*
4
1 1 2 2
1 1 2 2
2 2 1 2
2 2 2 1
2
1 0
0 1
2
1 3
3 1
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
7 ms |
2004 KB |
Output is correct |
7 |
Correct |
164 ms |
25964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
7 ms |
2004 KB |
Output is correct |
7 |
Correct |
164 ms |
25964 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
7 ms |
2004 KB |
Output is correct |
13 |
Correct |
158 ms |
26020 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
4 ms |
1492 KB |
Output is correct |
17 |
Correct |
71 ms |
16076 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
40 ms |
7696 KB |
Output is correct |
21 |
Correct |
159 ms |
25932 KB |
Output is correct |
22 |
Correct |
158 ms |
25916 KB |
Output is correct |
23 |
Correct |
163 ms |
26024 KB |
Output is correct |
24 |
Correct |
160 ms |
25976 KB |
Output is correct |
25 |
Correct |
69 ms |
16048 KB |
Output is correct |
26 |
Correct |
69 ms |
16032 KB |
Output is correct |
27 |
Correct |
160 ms |
26016 KB |
Output is correct |
28 |
Correct |
169 ms |
26016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
7 ms |
2080 KB |
Output is correct |
9 |
Correct |
163 ms |
27908 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
7 ms |
2048 KB |
Output is correct |
13 |
Correct |
158 ms |
28000 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
4 ms |
1620 KB |
Output is correct |
17 |
Correct |
74 ms |
18120 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
328 KB |
Output is correct |
21 |
Correct |
41 ms |
8200 KB |
Output is correct |
22 |
Correct |
159 ms |
28004 KB |
Output is correct |
23 |
Correct |
163 ms |
27932 KB |
Output is correct |
24 |
Correct |
163 ms |
27996 KB |
Output is correct |
25 |
Correct |
71 ms |
18076 KB |
Output is correct |
26 |
Correct |
70 ms |
17996 KB |
Output is correct |
27 |
Correct |
158 ms |
27928 KB |
Output is correct |
28 |
Correct |
165 ms |
27984 KB |
Output is correct |
29 |
Correct |
68 ms |
18072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
41 ms |
7728 KB |
Output is correct |
5 |
Correct |
163 ms |
26012 KB |
Output is correct |
6 |
Correct |
157 ms |
25932 KB |
Output is correct |
7 |
Correct |
163 ms |
25972 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
40 ms |
7768 KB |
Output is correct |
10 |
Correct |
174 ms |
26020 KB |
Output is correct |
11 |
Correct |
161 ms |
26048 KB |
Output is correct |
12 |
Correct |
162 ms |
26024 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
44 ms |
7736 KB |
Output is correct |
17 |
Correct |
166 ms |
26032 KB |
Output is correct |
18 |
Correct |
178 ms |
26012 KB |
Output is correct |
19 |
Correct |
159 ms |
26032 KB |
Output is correct |
20 |
Correct |
158 ms |
26020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
7 ms |
2004 KB |
Output is correct |
7 |
Correct |
164 ms |
25964 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
7 ms |
2004 KB |
Output is correct |
13 |
Correct |
158 ms |
26020 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
4 ms |
1492 KB |
Output is correct |
17 |
Correct |
71 ms |
16076 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
40 ms |
7696 KB |
Output is correct |
21 |
Correct |
159 ms |
25932 KB |
Output is correct |
22 |
Correct |
158 ms |
25916 KB |
Output is correct |
23 |
Correct |
163 ms |
26024 KB |
Output is correct |
24 |
Correct |
160 ms |
25976 KB |
Output is correct |
25 |
Correct |
69 ms |
16048 KB |
Output is correct |
26 |
Correct |
69 ms |
16032 KB |
Output is correct |
27 |
Correct |
160 ms |
26016 KB |
Output is correct |
28 |
Correct |
169 ms |
26016 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
7 ms |
2080 KB |
Output is correct |
37 |
Correct |
163 ms |
27908 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
328 KB |
Output is correct |
40 |
Correct |
7 ms |
2048 KB |
Output is correct |
41 |
Correct |
158 ms |
28000 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
4 ms |
1620 KB |
Output is correct |
45 |
Correct |
74 ms |
18120 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
1 ms |
328 KB |
Output is correct |
49 |
Correct |
41 ms |
8200 KB |
Output is correct |
50 |
Correct |
159 ms |
28004 KB |
Output is correct |
51 |
Correct |
163 ms |
27932 KB |
Output is correct |
52 |
Correct |
163 ms |
27996 KB |
Output is correct |
53 |
Correct |
71 ms |
18076 KB |
Output is correct |
54 |
Correct |
70 ms |
17996 KB |
Output is correct |
55 |
Correct |
158 ms |
27928 KB |
Output is correct |
56 |
Correct |
165 ms |
27984 KB |
Output is correct |
57 |
Correct |
68 ms |
18072 KB |
Output is correct |
58 |
Correct |
1 ms |
340 KB |
Output is correct |
59 |
Correct |
1 ms |
340 KB |
Output is correct |
60 |
Correct |
4 ms |
1592 KB |
Output is correct |
61 |
Correct |
72 ms |
17944 KB |
Output is correct |
62 |
Correct |
1 ms |
340 KB |
Output is correct |
63 |
Correct |
1 ms |
328 KB |
Output is correct |
64 |
Correct |
1 ms |
340 KB |
Output is correct |
65 |
Correct |
41 ms |
8272 KB |
Output is correct |
66 |
Correct |
75 ms |
18000 KB |
Output is correct |
67 |
Correct |
71 ms |
18068 KB |
Output is correct |
68 |
Correct |
70 ms |
17956 KB |
Output is correct |
69 |
Correct |
74 ms |
18076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
7 ms |
2004 KB |
Output is correct |
7 |
Correct |
164 ms |
25964 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
7 ms |
2004 KB |
Output is correct |
13 |
Correct |
158 ms |
26020 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
4 ms |
1492 KB |
Output is correct |
17 |
Correct |
71 ms |
16076 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
40 ms |
7696 KB |
Output is correct |
21 |
Correct |
159 ms |
25932 KB |
Output is correct |
22 |
Correct |
158 ms |
25916 KB |
Output is correct |
23 |
Correct |
163 ms |
26024 KB |
Output is correct |
24 |
Correct |
160 ms |
25976 KB |
Output is correct |
25 |
Correct |
69 ms |
16048 KB |
Output is correct |
26 |
Correct |
69 ms |
16032 KB |
Output is correct |
27 |
Correct |
160 ms |
26016 KB |
Output is correct |
28 |
Correct |
169 ms |
26016 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
7 ms |
2080 KB |
Output is correct |
37 |
Correct |
163 ms |
27908 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
328 KB |
Output is correct |
40 |
Correct |
7 ms |
2048 KB |
Output is correct |
41 |
Correct |
158 ms |
28000 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
4 ms |
1620 KB |
Output is correct |
45 |
Correct |
74 ms |
18120 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
1 ms |
328 KB |
Output is correct |
49 |
Correct |
41 ms |
8200 KB |
Output is correct |
50 |
Correct |
159 ms |
28004 KB |
Output is correct |
51 |
Correct |
163 ms |
27932 KB |
Output is correct |
52 |
Correct |
163 ms |
27996 KB |
Output is correct |
53 |
Correct |
71 ms |
18076 KB |
Output is correct |
54 |
Correct |
70 ms |
17996 KB |
Output is correct |
55 |
Correct |
158 ms |
27928 KB |
Output is correct |
56 |
Correct |
165 ms |
27984 KB |
Output is correct |
57 |
Correct |
68 ms |
18072 KB |
Output is correct |
58 |
Correct |
0 ms |
340 KB |
Output is correct |
59 |
Correct |
0 ms |
340 KB |
Output is correct |
60 |
Correct |
0 ms |
340 KB |
Output is correct |
61 |
Correct |
41 ms |
7728 KB |
Output is correct |
62 |
Correct |
163 ms |
26012 KB |
Output is correct |
63 |
Correct |
157 ms |
25932 KB |
Output is correct |
64 |
Correct |
163 ms |
25972 KB |
Output is correct |
65 |
Correct |
0 ms |
340 KB |
Output is correct |
66 |
Correct |
40 ms |
7768 KB |
Output is correct |
67 |
Correct |
174 ms |
26020 KB |
Output is correct |
68 |
Correct |
161 ms |
26048 KB |
Output is correct |
69 |
Correct |
162 ms |
26024 KB |
Output is correct |
70 |
Correct |
1 ms |
340 KB |
Output is correct |
71 |
Correct |
0 ms |
340 KB |
Output is correct |
72 |
Correct |
1 ms |
340 KB |
Output is correct |
73 |
Correct |
44 ms |
7736 KB |
Output is correct |
74 |
Correct |
166 ms |
26032 KB |
Output is correct |
75 |
Correct |
178 ms |
26012 KB |
Output is correct |
76 |
Correct |
159 ms |
26032 KB |
Output is correct |
77 |
Correct |
158 ms |
26020 KB |
Output is correct |
78 |
Correct |
1 ms |
340 KB |
Output is correct |
79 |
Correct |
1 ms |
340 KB |
Output is correct |
80 |
Correct |
4 ms |
1592 KB |
Output is correct |
81 |
Correct |
72 ms |
17944 KB |
Output is correct |
82 |
Correct |
1 ms |
340 KB |
Output is correct |
83 |
Correct |
1 ms |
328 KB |
Output is correct |
84 |
Correct |
1 ms |
340 KB |
Output is correct |
85 |
Correct |
41 ms |
8272 KB |
Output is correct |
86 |
Correct |
75 ms |
18000 KB |
Output is correct |
87 |
Correct |
71 ms |
18068 KB |
Output is correct |
88 |
Correct |
70 ms |
17956 KB |
Output is correct |
89 |
Correct |
74 ms |
18076 KB |
Output is correct |
90 |
Correct |
1 ms |
340 KB |
Output is correct |
91 |
Correct |
1 ms |
340 KB |
Output is correct |
92 |
Correct |
4 ms |
1620 KB |
Output is correct |
93 |
Correct |
77 ms |
17956 KB |
Output is correct |
94 |
Correct |
1 ms |
340 KB |
Output is correct |
95 |
Correct |
1 ms |
340 KB |
Output is correct |
96 |
Correct |
1 ms |
340 KB |
Output is correct |
97 |
Correct |
18 ms |
5716 KB |
Output is correct |
98 |
Correct |
66 ms |
17944 KB |
Output is correct |
99 |
Correct |
68 ms |
17960 KB |
Output is correct |
100 |
Correct |
68 ms |
17996 KB |
Output is correct |
101 |
Correct |
68 ms |
17948 KB |
Output is correct |
102 |
Correct |
70 ms |
17940 KB |
Output is correct |
103 |
Correct |
75 ms |
17996 KB |
Output is correct |
104 |
Correct |
62 ms |
17940 KB |
Output is correct |
105 |
Correct |
85 ms |
17992 KB |
Output is correct |