#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]){
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 |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
1552 KB |
Output is correct |
7 |
Correct |
157 ms |
26272 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 |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
1552 KB |
Output is correct |
7 |
Correct |
157 ms |
26272 KB |
Output is correct |
8 |
Correct |
0 ms |
344 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 |
157 ms |
22000 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 |
74 ms |
14884 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
38 ms |
5848 KB |
Output is correct |
21 |
Correct |
154 ms |
22564 KB |
Output is correct |
22 |
Correct |
151 ms |
22068 KB |
Output is correct |
23 |
Correct |
161 ms |
24148 KB |
Output is correct |
24 |
Correct |
156 ms |
22356 KB |
Output is correct |
25 |
Correct |
70 ms |
12628 KB |
Output is correct |
26 |
Correct |
66 ms |
12116 KB |
Output is correct |
27 |
Correct |
158 ms |
25384 KB |
Output is correct |
28 |
Correct |
155 ms |
22096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
7 ms |
1372 KB |
Output is correct |
9 |
Correct |
148 ms |
24088 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
7 ms |
1644 KB |
Output is correct |
13 |
Correct |
159 ms |
28048 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 |
1116 KB |
Output is correct |
17 |
Correct |
73 ms |
16912 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
39 ms |
6492 KB |
Output is correct |
22 |
Correct |
163 ms |
24720 KB |
Output is correct |
23 |
Correct |
152 ms |
24144 KB |
Output is correct |
24 |
Correct |
163 ms |
27472 KB |
Output is correct |
25 |
Correct |
66 ms |
14240 KB |
Output is correct |
26 |
Correct |
67 ms |
14676 KB |
Output is correct |
27 |
Correct |
152 ms |
24084 KB |
Output is correct |
28 |
Correct |
158 ms |
26196 KB |
Output is correct |
29 |
Correct |
65 ms |
14164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
38 ms |
6452 KB |
Output is correct |
5 |
Correct |
155 ms |
24656 KB |
Output is correct |
6 |
Correct |
151 ms |
24148 KB |
Output is correct |
7 |
Correct |
158 ms |
26136 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
39 ms |
6300 KB |
Output is correct |
10 |
Correct |
152 ms |
24608 KB |
Output is correct |
11 |
Correct |
151 ms |
24228 KB |
Output is correct |
12 |
Correct |
160 ms |
27300 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 |
38 ms |
6300 KB |
Output is correct |
17 |
Correct |
153 ms |
24660 KB |
Output is correct |
18 |
Correct |
157 ms |
24780 KB |
Output is correct |
19 |
Correct |
153 ms |
24400 KB |
Output is correct |
20 |
Correct |
154 ms |
23972 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 |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
1552 KB |
Output is correct |
7 |
Correct |
157 ms |
26272 KB |
Output is correct |
8 |
Correct |
0 ms |
344 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 |
157 ms |
22000 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 |
74 ms |
14884 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
38 ms |
5848 KB |
Output is correct |
21 |
Correct |
154 ms |
22564 KB |
Output is correct |
22 |
Correct |
151 ms |
22068 KB |
Output is correct |
23 |
Correct |
161 ms |
24148 KB |
Output is correct |
24 |
Correct |
156 ms |
22356 KB |
Output is correct |
25 |
Correct |
70 ms |
12628 KB |
Output is correct |
26 |
Correct |
66 ms |
12116 KB |
Output is correct |
27 |
Correct |
158 ms |
25384 KB |
Output is correct |
28 |
Correct |
155 ms |
22096 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
0 ms |
600 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
468 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
7 ms |
1372 KB |
Output is correct |
37 |
Correct |
148 ms |
24088 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
7 ms |
1644 KB |
Output is correct |
41 |
Correct |
159 ms |
28048 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
4 ms |
1116 KB |
Output is correct |
45 |
Correct |
73 ms |
16912 KB |
Output is correct |
46 |
Correct |
0 ms |
344 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
39 ms |
6492 KB |
Output is correct |
50 |
Correct |
163 ms |
24720 KB |
Output is correct |
51 |
Correct |
152 ms |
24144 KB |
Output is correct |
52 |
Correct |
163 ms |
27472 KB |
Output is correct |
53 |
Correct |
66 ms |
14240 KB |
Output is correct |
54 |
Correct |
67 ms |
14676 KB |
Output is correct |
55 |
Correct |
152 ms |
24084 KB |
Output is correct |
56 |
Correct |
158 ms |
26196 KB |
Output is correct |
57 |
Correct |
65 ms |
14164 KB |
Output is correct |
58 |
Correct |
0 ms |
344 KB |
Output is correct |
59 |
Correct |
1 ms |
344 KB |
Output is correct |
60 |
Correct |
3 ms |
1116 KB |
Output is correct |
61 |
Correct |
73 ms |
18600 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 |
43 ms |
6228 KB |
Output is correct |
66 |
Correct |
67 ms |
14880 KB |
Output is correct |
67 |
Correct |
68 ms |
14676 KB |
Output is correct |
68 |
Correct |
67 ms |
14416 KB |
Output is correct |
69 |
Correct |
62 ms |
14168 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 |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
1552 KB |
Output is correct |
7 |
Correct |
157 ms |
26272 KB |
Output is correct |
8 |
Correct |
0 ms |
344 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 |
157 ms |
22000 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 |
74 ms |
14884 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
38 ms |
5848 KB |
Output is correct |
21 |
Correct |
154 ms |
22564 KB |
Output is correct |
22 |
Correct |
151 ms |
22068 KB |
Output is correct |
23 |
Correct |
161 ms |
24148 KB |
Output is correct |
24 |
Correct |
156 ms |
22356 KB |
Output is correct |
25 |
Correct |
70 ms |
12628 KB |
Output is correct |
26 |
Correct |
66 ms |
12116 KB |
Output is correct |
27 |
Correct |
158 ms |
25384 KB |
Output is correct |
28 |
Correct |
155 ms |
22096 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
0 ms |
600 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
468 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
7 ms |
1372 KB |
Output is correct |
37 |
Correct |
148 ms |
24088 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
7 ms |
1644 KB |
Output is correct |
41 |
Correct |
159 ms |
28048 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
4 ms |
1116 KB |
Output is correct |
45 |
Correct |
73 ms |
16912 KB |
Output is correct |
46 |
Correct |
0 ms |
344 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
39 ms |
6492 KB |
Output is correct |
50 |
Correct |
163 ms |
24720 KB |
Output is correct |
51 |
Correct |
152 ms |
24144 KB |
Output is correct |
52 |
Correct |
163 ms |
27472 KB |
Output is correct |
53 |
Correct |
66 ms |
14240 KB |
Output is correct |
54 |
Correct |
67 ms |
14676 KB |
Output is correct |
55 |
Correct |
152 ms |
24084 KB |
Output is correct |
56 |
Correct |
158 ms |
26196 KB |
Output is correct |
57 |
Correct |
65 ms |
14164 KB |
Output is correct |
58 |
Correct |
0 ms |
600 KB |
Output is correct |
59 |
Correct |
0 ms |
344 KB |
Output is correct |
60 |
Correct |
1 ms |
348 KB |
Output is correct |
61 |
Correct |
38 ms |
6452 KB |
Output is correct |
62 |
Correct |
155 ms |
24656 KB |
Output is correct |
63 |
Correct |
151 ms |
24148 KB |
Output is correct |
64 |
Correct |
158 ms |
26136 KB |
Output is correct |
65 |
Correct |
0 ms |
348 KB |
Output is correct |
66 |
Correct |
39 ms |
6300 KB |
Output is correct |
67 |
Correct |
152 ms |
24608 KB |
Output is correct |
68 |
Correct |
151 ms |
24228 KB |
Output is correct |
69 |
Correct |
160 ms |
27300 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 |
38 ms |
6300 KB |
Output is correct |
74 |
Correct |
153 ms |
24660 KB |
Output is correct |
75 |
Correct |
157 ms |
24780 KB |
Output is correct |
76 |
Correct |
153 ms |
24400 KB |
Output is correct |
77 |
Correct |
154 ms |
23972 KB |
Output is correct |
78 |
Correct |
0 ms |
344 KB |
Output is correct |
79 |
Correct |
1 ms |
344 KB |
Output is correct |
80 |
Correct |
3 ms |
1116 KB |
Output is correct |
81 |
Correct |
73 ms |
18600 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 |
43 ms |
6228 KB |
Output is correct |
86 |
Correct |
67 ms |
14880 KB |
Output is correct |
87 |
Correct |
68 ms |
14676 KB |
Output is correct |
88 |
Correct |
67 ms |
14416 KB |
Output is correct |
89 |
Correct |
62 ms |
14168 KB |
Output is correct |
90 |
Correct |
1 ms |
348 KB |
Output is correct |
91 |
Correct |
0 ms |
348 KB |
Output is correct |
92 |
Correct |
4 ms |
1112 KB |
Output is correct |
93 |
Correct |
73 ms |
18372 KB |
Output is correct |
94 |
Correct |
0 ms |
348 KB |
Output is correct |
95 |
Correct |
0 ms |
348 KB |
Output is correct |
96 |
Correct |
0 ms |
344 KB |
Output is correct |
97 |
Correct |
17 ms |
3928 KB |
Output is correct |
98 |
Correct |
64 ms |
14676 KB |
Output is correct |
99 |
Correct |
72 ms |
14672 KB |
Output is correct |
100 |
Correct |
66 ms |
14368 KB |
Output is correct |
101 |
Correct |
63 ms |
14096 KB |
Output is correct |
102 |
Incorrect |
163 ms |
28328 KB |
Answer gives possible 1 while actual possible 0 |
103 |
Halted |
0 ms |
0 KB |
- |