#include<bits/stdc++.h>
#include "supertrees.h"
#define ll int
#define ld long double
#define fs first
#define sc second
#define debug(y) cout<<y,exit(0)
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 1e3 + 9;
const ll mod = 1e9 + 7;
const ll base = 31;
vector<vector<ll>> ans;
vector<LL> g1,g2;
ll n,ok[N];
int construct(vector<vector<int>> p){
n = p.size(); ans = p;
for (ll i = 0;i < n;i++){
for (ll j = 0;j < n;j++) ans[i][j] = 0;
}
for (ll i = 0;i < n;i++)
for (ll j = 0;j < n;j++) if (p[i][j] == 3) return 0;
for (ll i = 0;i < n;i++){
ll now = 0;
while(p[i][now] != 1) now++;
if (now != i){
if (p[i] != p[now]) return 0;
ans[now][i] = ans[i][now] = 1;
}
else ok[i] = 1;
}
for(ll i = 0;i < n;i++) if(ok[i]){
ll cc = 0;
while(!p[i][cc]) cc++;
for(ll j = 0;j < n;j++)
if((p[cc][j] == 0) ^ (p[i][j] == 0)) return 0;
if(cc == i){
ll now = i;
for(ll j = i + 1;j < n;j++)
if(ok[j] && p[i][j]){
ans[now][j] = 1; ans[j][now] = 1;
now = j;
}
if(now == i);
else if(ans[now][i]) return 0;
else{
ans[now][i] = 1; ans[i][now] = 1;
}
}
}
build(ans);
return 1;
}
/*
int main(){
ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
#define task "test"
if (fopen(task".inp","r")){
freopen(task".inp","r",stdin);
//freopen(task".out","w",stdout);
}
ll sz; vector<vector<ll>> p;
cin>>sz;
for (ll i = 0;i < sz;i++){
vector<ll> tmp; ll x;
for (ll j = 0;j < sz;j++) cin>>x,tmp.push_back(x);
p.push_back(tmp);
}
cout<<construct(p)<<"\n";
}
*/
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
7 ms |
1100 KB |
Output is correct |
7 |
Correct |
166 ms |
22020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
7 ms |
1100 KB |
Output is correct |
7 |
Correct |
166 ms |
22020 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
7 ms |
1100 KB |
Output is correct |
13 |
Correct |
167 ms |
22028 KB |
Output is correct |
14 |
Correct |
0 ms |
220 KB |
Output is correct |
15 |
Correct |
0 ms |
216 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
76 ms |
12032 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
44 ms |
5752 KB |
Output is correct |
21 |
Correct |
165 ms |
21956 KB |
Output is correct |
22 |
Correct |
167 ms |
21984 KB |
Output is correct |
23 |
Correct |
177 ms |
22016 KB |
Output is correct |
24 |
Correct |
171 ms |
22024 KB |
Output is correct |
25 |
Correct |
74 ms |
12028 KB |
Output is correct |
26 |
Correct |
70 ms |
12028 KB |
Output is correct |
27 |
Correct |
176 ms |
22028 KB |
Output is correct |
28 |
Correct |
176 ms |
22028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
292 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
8 ms |
1208 KB |
Output is correct |
9 |
Correct |
167 ms |
23968 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
8 ms |
1172 KB |
Output is correct |
13 |
Correct |
169 ms |
23920 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
208 KB |
Output is correct |
16 |
Correct |
3 ms |
856 KB |
Output is correct |
17 |
Correct |
77 ms |
14092 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
216 KB |
Output is correct |
20 |
Correct |
0 ms |
216 KB |
Output is correct |
21 |
Correct |
44 ms |
6220 KB |
Output is correct |
22 |
Correct |
168 ms |
23936 KB |
Output is correct |
23 |
Correct |
166 ms |
23984 KB |
Output is correct |
24 |
Correct |
177 ms |
23916 KB |
Output is correct |
25 |
Correct |
70 ms |
14068 KB |
Output is correct |
26 |
Correct |
70 ms |
14068 KB |
Output is correct |
27 |
Correct |
173 ms |
23984 KB |
Output is correct |
28 |
Correct |
187 ms |
23920 KB |
Output is correct |
29 |
Correct |
75 ms |
14000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
44 ms |
6248 KB |
Output is correct |
5 |
Correct |
172 ms |
24008 KB |
Output is correct |
6 |
Correct |
180 ms |
23952 KB |
Output is correct |
7 |
Correct |
174 ms |
23972 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
44 ms |
6212 KB |
Output is correct |
10 |
Correct |
173 ms |
24048 KB |
Output is correct |
11 |
Correct |
166 ms |
23944 KB |
Output is correct |
12 |
Correct |
175 ms |
23928 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
43 ms |
6160 KB |
Output is correct |
17 |
Correct |
187 ms |
24048 KB |
Output is correct |
18 |
Correct |
173 ms |
23920 KB |
Output is correct |
19 |
Correct |
165 ms |
23932 KB |
Output is correct |
20 |
Correct |
171 ms |
23888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
7 ms |
1100 KB |
Output is correct |
7 |
Correct |
166 ms |
22020 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
7 ms |
1100 KB |
Output is correct |
13 |
Correct |
167 ms |
22028 KB |
Output is correct |
14 |
Correct |
0 ms |
220 KB |
Output is correct |
15 |
Correct |
0 ms |
216 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
76 ms |
12032 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
44 ms |
5752 KB |
Output is correct |
21 |
Correct |
165 ms |
21956 KB |
Output is correct |
22 |
Correct |
167 ms |
21984 KB |
Output is correct |
23 |
Correct |
177 ms |
22016 KB |
Output is correct |
24 |
Correct |
171 ms |
22024 KB |
Output is correct |
25 |
Correct |
74 ms |
12028 KB |
Output is correct |
26 |
Correct |
70 ms |
12028 KB |
Output is correct |
27 |
Correct |
176 ms |
22028 KB |
Output is correct |
28 |
Correct |
176 ms |
22028 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
0 ms |
292 KB |
Output is correct |
34 |
Correct |
0 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
8 ms |
1208 KB |
Output is correct |
37 |
Correct |
167 ms |
23968 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
0 ms |
204 KB |
Output is correct |
40 |
Correct |
8 ms |
1172 KB |
Output is correct |
41 |
Correct |
169 ms |
23920 KB |
Output is correct |
42 |
Correct |
0 ms |
204 KB |
Output is correct |
43 |
Correct |
0 ms |
208 KB |
Output is correct |
44 |
Correct |
3 ms |
856 KB |
Output is correct |
45 |
Correct |
77 ms |
14092 KB |
Output is correct |
46 |
Correct |
1 ms |
204 KB |
Output is correct |
47 |
Correct |
1 ms |
216 KB |
Output is correct |
48 |
Correct |
0 ms |
216 KB |
Output is correct |
49 |
Correct |
44 ms |
6220 KB |
Output is correct |
50 |
Correct |
168 ms |
23936 KB |
Output is correct |
51 |
Correct |
166 ms |
23984 KB |
Output is correct |
52 |
Correct |
177 ms |
23916 KB |
Output is correct |
53 |
Correct |
70 ms |
14068 KB |
Output is correct |
54 |
Correct |
70 ms |
14068 KB |
Output is correct |
55 |
Correct |
173 ms |
23984 KB |
Output is correct |
56 |
Correct |
187 ms |
23920 KB |
Output is correct |
57 |
Correct |
75 ms |
14000 KB |
Output is correct |
58 |
Correct |
0 ms |
204 KB |
Output is correct |
59 |
Correct |
0 ms |
296 KB |
Output is correct |
60 |
Correct |
3 ms |
844 KB |
Output is correct |
61 |
Correct |
76 ms |
14064 KB |
Output is correct |
62 |
Correct |
0 ms |
204 KB |
Output is correct |
63 |
Correct |
0 ms |
204 KB |
Output is correct |
64 |
Correct |
0 ms |
204 KB |
Output is correct |
65 |
Correct |
44 ms |
6136 KB |
Output is correct |
66 |
Correct |
71 ms |
14072 KB |
Output is correct |
67 |
Correct |
75 ms |
14064 KB |
Output is correct |
68 |
Correct |
72 ms |
14064 KB |
Output is correct |
69 |
Correct |
70 ms |
14060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
7 ms |
1100 KB |
Output is correct |
7 |
Correct |
166 ms |
22020 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
7 ms |
1100 KB |
Output is correct |
13 |
Correct |
167 ms |
22028 KB |
Output is correct |
14 |
Correct |
0 ms |
220 KB |
Output is correct |
15 |
Correct |
0 ms |
216 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
76 ms |
12032 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
44 ms |
5752 KB |
Output is correct |
21 |
Correct |
165 ms |
21956 KB |
Output is correct |
22 |
Correct |
167 ms |
21984 KB |
Output is correct |
23 |
Correct |
177 ms |
22016 KB |
Output is correct |
24 |
Correct |
171 ms |
22024 KB |
Output is correct |
25 |
Correct |
74 ms |
12028 KB |
Output is correct |
26 |
Correct |
70 ms |
12028 KB |
Output is correct |
27 |
Correct |
176 ms |
22028 KB |
Output is correct |
28 |
Correct |
176 ms |
22028 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
0 ms |
292 KB |
Output is correct |
34 |
Correct |
0 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
8 ms |
1208 KB |
Output is correct |
37 |
Correct |
167 ms |
23968 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
0 ms |
204 KB |
Output is correct |
40 |
Correct |
8 ms |
1172 KB |
Output is correct |
41 |
Correct |
169 ms |
23920 KB |
Output is correct |
42 |
Correct |
0 ms |
204 KB |
Output is correct |
43 |
Correct |
0 ms |
208 KB |
Output is correct |
44 |
Correct |
3 ms |
856 KB |
Output is correct |
45 |
Correct |
77 ms |
14092 KB |
Output is correct |
46 |
Correct |
1 ms |
204 KB |
Output is correct |
47 |
Correct |
1 ms |
216 KB |
Output is correct |
48 |
Correct |
0 ms |
216 KB |
Output is correct |
49 |
Correct |
44 ms |
6220 KB |
Output is correct |
50 |
Correct |
168 ms |
23936 KB |
Output is correct |
51 |
Correct |
166 ms |
23984 KB |
Output is correct |
52 |
Correct |
177 ms |
23916 KB |
Output is correct |
53 |
Correct |
70 ms |
14068 KB |
Output is correct |
54 |
Correct |
70 ms |
14068 KB |
Output is correct |
55 |
Correct |
173 ms |
23984 KB |
Output is correct |
56 |
Correct |
187 ms |
23920 KB |
Output is correct |
57 |
Correct |
75 ms |
14000 KB |
Output is correct |
58 |
Correct |
1 ms |
204 KB |
Output is correct |
59 |
Correct |
0 ms |
204 KB |
Output is correct |
60 |
Correct |
1 ms |
204 KB |
Output is correct |
61 |
Correct |
44 ms |
6248 KB |
Output is correct |
62 |
Correct |
172 ms |
24008 KB |
Output is correct |
63 |
Correct |
180 ms |
23952 KB |
Output is correct |
64 |
Correct |
174 ms |
23972 KB |
Output is correct |
65 |
Correct |
0 ms |
204 KB |
Output is correct |
66 |
Correct |
44 ms |
6212 KB |
Output is correct |
67 |
Correct |
173 ms |
24048 KB |
Output is correct |
68 |
Correct |
166 ms |
23944 KB |
Output is correct |
69 |
Correct |
175 ms |
23928 KB |
Output is correct |
70 |
Correct |
0 ms |
204 KB |
Output is correct |
71 |
Correct |
0 ms |
204 KB |
Output is correct |
72 |
Correct |
0 ms |
204 KB |
Output is correct |
73 |
Correct |
43 ms |
6160 KB |
Output is correct |
74 |
Correct |
187 ms |
24048 KB |
Output is correct |
75 |
Correct |
173 ms |
23920 KB |
Output is correct |
76 |
Correct |
165 ms |
23932 KB |
Output is correct |
77 |
Correct |
171 ms |
23888 KB |
Output is correct |
78 |
Correct |
0 ms |
204 KB |
Output is correct |
79 |
Correct |
0 ms |
296 KB |
Output is correct |
80 |
Correct |
3 ms |
844 KB |
Output is correct |
81 |
Correct |
76 ms |
14064 KB |
Output is correct |
82 |
Correct |
0 ms |
204 KB |
Output is correct |
83 |
Correct |
0 ms |
204 KB |
Output is correct |
84 |
Correct |
0 ms |
204 KB |
Output is correct |
85 |
Correct |
44 ms |
6136 KB |
Output is correct |
86 |
Correct |
71 ms |
14072 KB |
Output is correct |
87 |
Correct |
75 ms |
14064 KB |
Output is correct |
88 |
Correct |
72 ms |
14064 KB |
Output is correct |
89 |
Correct |
70 ms |
14060 KB |
Output is correct |
90 |
Correct |
0 ms |
204 KB |
Output is correct |
91 |
Correct |
0 ms |
204 KB |
Output is correct |
92 |
Correct |
5 ms |
844 KB |
Output is correct |
93 |
Correct |
79 ms |
14080 KB |
Output is correct |
94 |
Correct |
0 ms |
204 KB |
Output is correct |
95 |
Correct |
0 ms |
204 KB |
Output is correct |
96 |
Correct |
0 ms |
204 KB |
Output is correct |
97 |
Correct |
18 ms |
3704 KB |
Output is correct |
98 |
Correct |
70 ms |
14060 KB |
Output is correct |
99 |
Correct |
71 ms |
14060 KB |
Output is correct |
100 |
Correct |
70 ms |
14060 KB |
Output is correct |
101 |
Correct |
68 ms |
14072 KB |
Output is correct |
102 |
Correct |
67 ms |
14064 KB |
Output is correct |
103 |
Correct |
67 ms |
14064 KB |
Output is correct |
104 |
Correct |
71 ms |
14080 KB |
Output is correct |
105 |
Correct |
73 ms |
14076 KB |
Output is correct |