#include "supertrees.h"
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define all(v) v.begin(), v.end()
#define pb push_back
#define ss second
#define ff first
#define vt vector
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;
const ll inf = 1e18;
const int mod = 1e9+7;
const int maxn = 1000 + 2;
vector<int> g[maxn];
int x;
int h[maxn], oh[maxn], used[maxn];
bool two[maxn], three[maxn];
bool was[maxn];
void dfs(int v){
h[v] = x;
was[v] = 1;
for(auto i : g[v]){
if(!was[i]){
dfs(i);
}
}
}
int construct(vector<vector<int>> p) {
int n = p.size();
vector<vector<int>> ans(n);
for(int i = 0; i < n; i++)ans[i].resize(n);
for(int i = 0; i < n; i++){
for(int j = 0; j <= i; j++){
if(i == j){
if(p[i][i] != 1)return 0;
continue;
}
if(p[i][j] == 3)return 0;
if(p[i][j]){
g[j].pb(i);
g[i].pb(j);
}
if(p[i][j] != p[j][i]){
return 0;
}
}
}
for(int i = 0; i < n; i++){
if(!was[i]){
x = i;
dfs(i);
}
}
for(int i = 0; i < n; i++){
oh[i] = used[i] = -1;
for(int j = 0; j < n; j++){
if(h[i] == h[j] && p[i][j] == 0){
return 0;
}
if(h[i] == h[j]){
if(p[i][j] == 2){
two[h[i]] = 1;
}
else if(p[i][j] == 3){
three[h[i]] = 1;
}
if(two[h[i]] && three[h[i]]){
return 0;
}
}
}
}
vt<int> unq;
for(int i = 0; i < n; i++){
if(oh[i] == -1){
unq.pb(i);
oh[i] = i;
for(auto j : g[i]){
if(p[i][j] == 1){
if(oh[j] != -1){
return 0;
}
oh[j] = i;
ans[i][j] = ans[j][i] = 1;
}
}
}
}
int sz = unq.size();
for(int I = 0; I < sz; I++){
int i = unq[I];
if(used[i] != -1)continue;
used[i] = i;
if(h[i] != i)return 0;
if(!three[i] && !two[i])continue;
bool wt = 0;
if(three[i])wt = 1;
int o = -1, ls = -1, z = i;
for(int J = 0; J < sz; J++){
int j = unq[J];
if(p[i][j] <= 1)continue;
if(used[j] == -1){
used[j] = i;
if(o == -1){
o = j;
ans[i][o] = ans[o][i] = 1;
}
else {
if(ls == -1)ls = j;
ans[z][j] = ans[j][z] = 1;
z = j;
}
}
else return 0;
}
if(z == i)return 0;
ans[o][z] = ans[z][o] = 1;
if(wt && ls == z){
return 0;
}
else if(wt){
ans[z][i] = ans[i][z] = 1;
}
}
build(ans);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
600 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
1372 KB |
Output is correct |
7 |
Correct |
161 ms |
26148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
600 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
1372 KB |
Output is correct |
7 |
Correct |
161 ms |
26148 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 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 |
1116 KB |
Output is correct |
13 |
Correct |
167 ms |
22096 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
860 KB |
Output is correct |
17 |
Correct |
74 ms |
14848 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
39 ms |
5916 KB |
Output is correct |
21 |
Correct |
157 ms |
22608 KB |
Output is correct |
22 |
Correct |
158 ms |
22052 KB |
Output is correct |
23 |
Correct |
199 ms |
24148 KB |
Output is correct |
24 |
Correct |
156 ms |
22064 KB |
Output is correct |
25 |
Correct |
70 ms |
12596 KB |
Output is correct |
26 |
Correct |
65 ms |
12340 KB |
Output is correct |
27 |
Correct |
162 ms |
25532 KB |
Output is correct |
28 |
Correct |
161 ms |
22100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 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 |
1116 KB |
Output is correct |
9 |
Correct |
167 ms |
22068 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
7 ms |
1372 KB |
Output is correct |
13 |
Correct |
168 ms |
26684 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 |
860 KB |
Output is correct |
17 |
Correct |
73 ms |
14932 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 |
49 ms |
5960 KB |
Output is correct |
22 |
Correct |
162 ms |
22568 KB |
Output is correct |
23 |
Correct |
154 ms |
22064 KB |
Output is correct |
24 |
Correct |
164 ms |
25348 KB |
Output is correct |
25 |
Correct |
66 ms |
12308 KB |
Output is correct |
26 |
Correct |
66 ms |
12840 KB |
Output is correct |
27 |
Correct |
154 ms |
22052 KB |
Output is correct |
28 |
Correct |
164 ms |
24136 KB |
Output is correct |
29 |
Correct |
66 ms |
12116 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 |
600 KB |
Output is correct |
4 |
Correct |
41 ms |
5820 KB |
Output is correct |
5 |
Correct |
155 ms |
22576 KB |
Output is correct |
6 |
Correct |
153 ms |
22060 KB |
Output is correct |
7 |
Correct |
167 ms |
24120 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
40 ms |
5988 KB |
Output is correct |
10 |
Correct |
194 ms |
22560 KB |
Output is correct |
11 |
Correct |
160 ms |
22064 KB |
Output is correct |
12 |
Correct |
163 ms |
25284 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
39 ms |
5784 KB |
Output is correct |
17 |
Correct |
156 ms |
22608 KB |
Output is correct |
18 |
Correct |
156 ms |
22868 KB |
Output is correct |
19 |
Correct |
155 ms |
22208 KB |
Output is correct |
20 |
Correct |
174 ms |
22100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
600 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
1372 KB |
Output is correct |
7 |
Correct |
161 ms |
26148 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 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 |
1116 KB |
Output is correct |
13 |
Correct |
167 ms |
22096 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
860 KB |
Output is correct |
17 |
Correct |
74 ms |
14848 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
39 ms |
5916 KB |
Output is correct |
21 |
Correct |
157 ms |
22608 KB |
Output is correct |
22 |
Correct |
158 ms |
22052 KB |
Output is correct |
23 |
Correct |
199 ms |
24148 KB |
Output is correct |
24 |
Correct |
156 ms |
22064 KB |
Output is correct |
25 |
Correct |
70 ms |
12596 KB |
Output is correct |
26 |
Correct |
65 ms |
12340 KB |
Output is correct |
27 |
Correct |
162 ms |
25532 KB |
Output is correct |
28 |
Correct |
161 ms |
22100 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
344 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 |
1116 KB |
Output is correct |
37 |
Correct |
167 ms |
22068 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
7 ms |
1372 KB |
Output is correct |
41 |
Correct |
168 ms |
26684 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
3 ms |
860 KB |
Output is correct |
45 |
Correct |
73 ms |
14932 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 |
49 ms |
5960 KB |
Output is correct |
50 |
Correct |
162 ms |
22568 KB |
Output is correct |
51 |
Correct |
154 ms |
22064 KB |
Output is correct |
52 |
Correct |
164 ms |
25348 KB |
Output is correct |
53 |
Correct |
66 ms |
12308 KB |
Output is correct |
54 |
Correct |
66 ms |
12840 KB |
Output is correct |
55 |
Correct |
154 ms |
22052 KB |
Output is correct |
56 |
Correct |
164 ms |
24136 KB |
Output is correct |
57 |
Correct |
66 ms |
12116 KB |
Output is correct |
58 |
Correct |
0 ms |
344 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
3 ms |
1116 KB |
Output is correct |
61 |
Correct |
73 ms |
16616 KB |
Output is correct |
62 |
Correct |
0 ms |
348 KB |
Output is correct |
63 |
Correct |
0 ms |
348 KB |
Output is correct |
64 |
Correct |
0 ms |
348 KB |
Output is correct |
65 |
Correct |
39 ms |
5800 KB |
Output is correct |
66 |
Correct |
67 ms |
12884 KB |
Output is correct |
67 |
Correct |
70 ms |
12600 KB |
Output is correct |
68 |
Correct |
65 ms |
12336 KB |
Output is correct |
69 |
Correct |
66 ms |
12324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
600 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
1372 KB |
Output is correct |
7 |
Correct |
161 ms |
26148 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 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 |
1116 KB |
Output is correct |
13 |
Correct |
167 ms |
22096 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
860 KB |
Output is correct |
17 |
Correct |
74 ms |
14848 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
39 ms |
5916 KB |
Output is correct |
21 |
Correct |
157 ms |
22608 KB |
Output is correct |
22 |
Correct |
158 ms |
22052 KB |
Output is correct |
23 |
Correct |
199 ms |
24148 KB |
Output is correct |
24 |
Correct |
156 ms |
22064 KB |
Output is correct |
25 |
Correct |
70 ms |
12596 KB |
Output is correct |
26 |
Correct |
65 ms |
12340 KB |
Output is correct |
27 |
Correct |
162 ms |
25532 KB |
Output is correct |
28 |
Correct |
161 ms |
22100 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
344 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 |
1116 KB |
Output is correct |
37 |
Correct |
167 ms |
22068 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
7 ms |
1372 KB |
Output is correct |
41 |
Correct |
168 ms |
26684 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
3 ms |
860 KB |
Output is correct |
45 |
Correct |
73 ms |
14932 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 |
49 ms |
5960 KB |
Output is correct |
50 |
Correct |
162 ms |
22568 KB |
Output is correct |
51 |
Correct |
154 ms |
22064 KB |
Output is correct |
52 |
Correct |
164 ms |
25348 KB |
Output is correct |
53 |
Correct |
66 ms |
12308 KB |
Output is correct |
54 |
Correct |
66 ms |
12840 KB |
Output is correct |
55 |
Correct |
154 ms |
22052 KB |
Output is correct |
56 |
Correct |
164 ms |
24136 KB |
Output is correct |
57 |
Correct |
66 ms |
12116 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 |
600 KB |
Output is correct |
61 |
Correct |
41 ms |
5820 KB |
Output is correct |
62 |
Correct |
155 ms |
22576 KB |
Output is correct |
63 |
Correct |
153 ms |
22060 KB |
Output is correct |
64 |
Correct |
167 ms |
24120 KB |
Output is correct |
65 |
Correct |
0 ms |
348 KB |
Output is correct |
66 |
Correct |
40 ms |
5988 KB |
Output is correct |
67 |
Correct |
194 ms |
22560 KB |
Output is correct |
68 |
Correct |
160 ms |
22064 KB |
Output is correct |
69 |
Correct |
163 ms |
25284 KB |
Output is correct |
70 |
Correct |
0 ms |
348 KB |
Output is correct |
71 |
Correct |
0 ms |
348 KB |
Output is correct |
72 |
Correct |
1 ms |
348 KB |
Output is correct |
73 |
Correct |
39 ms |
5784 KB |
Output is correct |
74 |
Correct |
156 ms |
22608 KB |
Output is correct |
75 |
Correct |
156 ms |
22868 KB |
Output is correct |
76 |
Correct |
155 ms |
22208 KB |
Output is correct |
77 |
Correct |
174 ms |
22100 KB |
Output is correct |
78 |
Correct |
0 ms |
344 KB |
Output is correct |
79 |
Correct |
0 ms |
348 KB |
Output is correct |
80 |
Correct |
3 ms |
1116 KB |
Output is correct |
81 |
Correct |
73 ms |
16616 KB |
Output is correct |
82 |
Correct |
0 ms |
348 KB |
Output is correct |
83 |
Correct |
0 ms |
348 KB |
Output is correct |
84 |
Correct |
0 ms |
348 KB |
Output is correct |
85 |
Correct |
39 ms |
5800 KB |
Output is correct |
86 |
Correct |
67 ms |
12884 KB |
Output is correct |
87 |
Correct |
70 ms |
12600 KB |
Output is correct |
88 |
Correct |
65 ms |
12336 KB |
Output is correct |
89 |
Correct |
66 ms |
12324 KB |
Output is correct |
90 |
Correct |
0 ms |
344 KB |
Output is correct |
91 |
Correct |
0 ms |
344 KB |
Output is correct |
92 |
Correct |
3 ms |
860 KB |
Output is correct |
93 |
Correct |
66 ms |
12076 KB |
Output is correct |
94 |
Correct |
0 ms |
500 KB |
Output is correct |
95 |
Correct |
0 ms |
348 KB |
Output is correct |
96 |
Correct |
1 ms |
348 KB |
Output is correct |
97 |
Correct |
17 ms |
3248 KB |
Output is correct |
98 |
Correct |
66 ms |
12340 KB |
Output is correct |
99 |
Correct |
65 ms |
12344 KB |
Output is correct |
100 |
Correct |
67 ms |
12084 KB |
Output is correct |
101 |
Correct |
64 ms |
12064 KB |
Output is correct |
102 |
Correct |
65 ms |
12068 KB |
Output is correct |
103 |
Correct |
69 ms |
14160 KB |
Output is correct |
104 |
Correct |
64 ms |
14160 KB |
Output is correct |
105 |
Correct |
80 ms |
14112 KB |
Output is correct |