#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
// typedef long double ld;
#define F first
#define S second
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define REP(i,n) for(int i=0;i<(n);i++)
#define MP make_pair
#define pb push_back
#define eb emplace_back
const int maxn = 1005;
const int INF = 0x3f3f3f3f;
const ll INF64 = 1e18;
const ll MOD = ll(1e9+7);
int n;
vector<int> cmp;
bool vis[maxn];
std::vector<std::vector<int>> ans;
std::vector<std::vector<int>> p;
void dfs(int u){
vis[u]=1;
cmp.pb(u);
REP(v,n) if(v!=u&&p[u][v]&&!vis[v]){
dfs(v);
}
}
vector<int> _;
bool vis2[maxn];
void dfs2(int u){
vis2[u]=1;
_.pb(u);
REP(v,n) if(v!=u&&p[u][v]==1&&!vis2[v]){
dfs2(v);
}
}
void add(int x,int y){
ans[x][y]=ans[y][x]=1;
}
bool process(){
// cout<<"process: ";
// for(int i:cmp){
// cout<<i<<' ';
// }
// cout<<'\n';
int cnt2 = SZ(cmp) * SZ(cmp);
for(int i:cmp) vis2[i] = 0;
vector<int> ring;
for(int i:cmp) if(!vis2[i]){
_.clear();
dfs2(i);
// for(int j:_){
// cout<<j<<' ';
// }
// cout<<endl;
for(int x:_) for(int y:_){
if(p[x][y]!=1) return 0;
}
REP(i,SZ(_)-1){
add(_[i],_[i+1]);
}
ring.pb(_[0]);
cnt2 -= SZ(_) * SZ(_);
}
if(SZ(ring)==2){
return 0;
}
if(SZ(ring)>2){
ring.pb(ring[0]);
REP(i,SZ(ring)-1){
add(ring[i],ring[i+1]);
}
}
for(int x:cmp) for(int y:cmp) if(p[x][y]==2){
cnt2--;
}
if(cnt2!=0) return 0;
return 1;
}
int construct(std::vector<std::vector<int>> A) {
p=A;
n = p.size();
for (int i = 0; i < n; i++) {
std::vector<int> row;
row.resize(n);
ans.push_back(row);
}
int cnt0 = n*n;
REP(i,n) REP(j,n) if(p[i][j]==3) return 0;
bool flag = 1;
REP(i,n) if(!vis[i]){
cmp.clear();
dfs(i);
flag &= process();
if(!flag) return 0;
cnt0 -= SZ(cmp) * SZ(cmp);
}
REP(i,n) REP(j,n) if(p[i][j]==0) cnt0--;
if(cnt0!=0) return 0;
build(ans);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
10 ms |
1408 KB |
Output is correct |
7 |
Correct |
245 ms |
26104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
10 ms |
1408 KB |
Output is correct |
7 |
Correct |
245 ms |
26104 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
11 ms |
1408 KB |
Output is correct |
13 |
Correct |
255 ms |
25976 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
6 ms |
1024 KB |
Output is correct |
17 |
Correct |
129 ms |
16120 KB |
Output is correct |
18 |
Correct |
0 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
256 KB |
Output is correct |
20 |
Correct |
60 ms |
6776 KB |
Output is correct |
21 |
Correct |
245 ms |
26104 KB |
Output is correct |
22 |
Correct |
244 ms |
25976 KB |
Output is correct |
23 |
Correct |
250 ms |
26108 KB |
Output is correct |
24 |
Correct |
243 ms |
26104 KB |
Output is correct |
25 |
Correct |
107 ms |
16120 KB |
Output is correct |
26 |
Correct |
126 ms |
16248 KB |
Output is correct |
27 |
Correct |
248 ms |
26104 KB |
Output is correct |
28 |
Correct |
244 ms |
26092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
0 ms |
256 KB |
Output is correct |
8 |
Correct |
10 ms |
1408 KB |
Output is correct |
9 |
Correct |
240 ms |
26112 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
10 ms |
1408 KB |
Output is correct |
13 |
Correct |
239 ms |
26104 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
8 ms |
1024 KB |
Output is correct |
17 |
Correct |
126 ms |
16120 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
256 KB |
Output is correct |
20 |
Correct |
1 ms |
256 KB |
Output is correct |
21 |
Correct |
60 ms |
6776 KB |
Output is correct |
22 |
Correct |
250 ms |
26104 KB |
Output is correct |
23 |
Correct |
240 ms |
26136 KB |
Output is correct |
24 |
Correct |
248 ms |
26108 KB |
Output is correct |
25 |
Correct |
105 ms |
16120 KB |
Output is correct |
26 |
Correct |
138 ms |
16120 KB |
Output is correct |
27 |
Correct |
242 ms |
25980 KB |
Output is correct |
28 |
Correct |
250 ms |
26104 KB |
Output is correct |
29 |
Correct |
105 ms |
16120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
60 ms |
6776 KB |
Output is correct |
5 |
Correct |
266 ms |
25976 KB |
Output is correct |
6 |
Correct |
243 ms |
25976 KB |
Output is correct |
7 |
Correct |
257 ms |
26232 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
60 ms |
6776 KB |
Output is correct |
10 |
Correct |
246 ms |
26104 KB |
Output is correct |
11 |
Correct |
251 ms |
26140 KB |
Output is correct |
12 |
Correct |
245 ms |
26104 KB |
Output is correct |
13 |
Correct |
0 ms |
256 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
61 ms |
6904 KB |
Output is correct |
17 |
Correct |
241 ms |
26104 KB |
Output is correct |
18 |
Correct |
247 ms |
26104 KB |
Output is correct |
19 |
Correct |
242 ms |
25976 KB |
Output is correct |
20 |
Correct |
238 ms |
26104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
10 ms |
1408 KB |
Output is correct |
7 |
Correct |
245 ms |
26104 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
11 ms |
1408 KB |
Output is correct |
13 |
Correct |
255 ms |
25976 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
6 ms |
1024 KB |
Output is correct |
17 |
Correct |
129 ms |
16120 KB |
Output is correct |
18 |
Correct |
0 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
256 KB |
Output is correct |
20 |
Correct |
60 ms |
6776 KB |
Output is correct |
21 |
Correct |
245 ms |
26104 KB |
Output is correct |
22 |
Correct |
244 ms |
25976 KB |
Output is correct |
23 |
Correct |
250 ms |
26108 KB |
Output is correct |
24 |
Correct |
243 ms |
26104 KB |
Output is correct |
25 |
Correct |
107 ms |
16120 KB |
Output is correct |
26 |
Correct |
126 ms |
16248 KB |
Output is correct |
27 |
Correct |
248 ms |
26104 KB |
Output is correct |
28 |
Correct |
244 ms |
26092 KB |
Output is correct |
29 |
Correct |
1 ms |
256 KB |
Output is correct |
30 |
Correct |
0 ms |
256 KB |
Output is correct |
31 |
Correct |
0 ms |
256 KB |
Output is correct |
32 |
Correct |
0 ms |
256 KB |
Output is correct |
33 |
Correct |
0 ms |
256 KB |
Output is correct |
34 |
Correct |
1 ms |
256 KB |
Output is correct |
35 |
Correct |
0 ms |
256 KB |
Output is correct |
36 |
Correct |
10 ms |
1408 KB |
Output is correct |
37 |
Correct |
240 ms |
26112 KB |
Output is correct |
38 |
Correct |
0 ms |
256 KB |
Output is correct |
39 |
Correct |
1 ms |
256 KB |
Output is correct |
40 |
Correct |
10 ms |
1408 KB |
Output is correct |
41 |
Correct |
239 ms |
26104 KB |
Output is correct |
42 |
Correct |
1 ms |
256 KB |
Output is correct |
43 |
Correct |
0 ms |
256 KB |
Output is correct |
44 |
Correct |
8 ms |
1024 KB |
Output is correct |
45 |
Correct |
126 ms |
16120 KB |
Output is correct |
46 |
Correct |
1 ms |
256 KB |
Output is correct |
47 |
Correct |
0 ms |
256 KB |
Output is correct |
48 |
Correct |
1 ms |
256 KB |
Output is correct |
49 |
Correct |
60 ms |
6776 KB |
Output is correct |
50 |
Correct |
250 ms |
26104 KB |
Output is correct |
51 |
Correct |
240 ms |
26136 KB |
Output is correct |
52 |
Correct |
248 ms |
26108 KB |
Output is correct |
53 |
Correct |
105 ms |
16120 KB |
Output is correct |
54 |
Correct |
138 ms |
16120 KB |
Output is correct |
55 |
Correct |
242 ms |
25980 KB |
Output is correct |
56 |
Correct |
250 ms |
26104 KB |
Output is correct |
57 |
Correct |
105 ms |
16120 KB |
Output is correct |
58 |
Correct |
0 ms |
256 KB |
Output is correct |
59 |
Correct |
0 ms |
256 KB |
Output is correct |
60 |
Correct |
8 ms |
1024 KB |
Output is correct |
61 |
Correct |
123 ms |
16120 KB |
Output is correct |
62 |
Correct |
1 ms |
256 KB |
Output is correct |
63 |
Correct |
0 ms |
256 KB |
Output is correct |
64 |
Correct |
0 ms |
256 KB |
Output is correct |
65 |
Correct |
60 ms |
6776 KB |
Output is correct |
66 |
Correct |
102 ms |
16120 KB |
Output is correct |
67 |
Correct |
106 ms |
16120 KB |
Output is correct |
68 |
Correct |
102 ms |
16120 KB |
Output is correct |
69 |
Correct |
110 ms |
16120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
10 ms |
1408 KB |
Output is correct |
7 |
Correct |
245 ms |
26104 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
11 ms |
1408 KB |
Output is correct |
13 |
Correct |
255 ms |
25976 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
6 ms |
1024 KB |
Output is correct |
17 |
Correct |
129 ms |
16120 KB |
Output is correct |
18 |
Correct |
0 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
256 KB |
Output is correct |
20 |
Correct |
60 ms |
6776 KB |
Output is correct |
21 |
Correct |
245 ms |
26104 KB |
Output is correct |
22 |
Correct |
244 ms |
25976 KB |
Output is correct |
23 |
Correct |
250 ms |
26108 KB |
Output is correct |
24 |
Correct |
243 ms |
26104 KB |
Output is correct |
25 |
Correct |
107 ms |
16120 KB |
Output is correct |
26 |
Correct |
126 ms |
16248 KB |
Output is correct |
27 |
Correct |
248 ms |
26104 KB |
Output is correct |
28 |
Correct |
244 ms |
26092 KB |
Output is correct |
29 |
Correct |
1 ms |
256 KB |
Output is correct |
30 |
Correct |
0 ms |
256 KB |
Output is correct |
31 |
Correct |
0 ms |
256 KB |
Output is correct |
32 |
Correct |
0 ms |
256 KB |
Output is correct |
33 |
Correct |
0 ms |
256 KB |
Output is correct |
34 |
Correct |
1 ms |
256 KB |
Output is correct |
35 |
Correct |
0 ms |
256 KB |
Output is correct |
36 |
Correct |
10 ms |
1408 KB |
Output is correct |
37 |
Correct |
240 ms |
26112 KB |
Output is correct |
38 |
Correct |
0 ms |
256 KB |
Output is correct |
39 |
Correct |
1 ms |
256 KB |
Output is correct |
40 |
Correct |
10 ms |
1408 KB |
Output is correct |
41 |
Correct |
239 ms |
26104 KB |
Output is correct |
42 |
Correct |
1 ms |
256 KB |
Output is correct |
43 |
Correct |
0 ms |
256 KB |
Output is correct |
44 |
Correct |
8 ms |
1024 KB |
Output is correct |
45 |
Correct |
126 ms |
16120 KB |
Output is correct |
46 |
Correct |
1 ms |
256 KB |
Output is correct |
47 |
Correct |
0 ms |
256 KB |
Output is correct |
48 |
Correct |
1 ms |
256 KB |
Output is correct |
49 |
Correct |
60 ms |
6776 KB |
Output is correct |
50 |
Correct |
250 ms |
26104 KB |
Output is correct |
51 |
Correct |
240 ms |
26136 KB |
Output is correct |
52 |
Correct |
248 ms |
26108 KB |
Output is correct |
53 |
Correct |
105 ms |
16120 KB |
Output is correct |
54 |
Correct |
138 ms |
16120 KB |
Output is correct |
55 |
Correct |
242 ms |
25980 KB |
Output is correct |
56 |
Correct |
250 ms |
26104 KB |
Output is correct |
57 |
Correct |
105 ms |
16120 KB |
Output is correct |
58 |
Correct |
1 ms |
256 KB |
Output is correct |
59 |
Correct |
1 ms |
384 KB |
Output is correct |
60 |
Correct |
0 ms |
256 KB |
Output is correct |
61 |
Correct |
60 ms |
6776 KB |
Output is correct |
62 |
Correct |
266 ms |
25976 KB |
Output is correct |
63 |
Correct |
243 ms |
25976 KB |
Output is correct |
64 |
Correct |
257 ms |
26232 KB |
Output is correct |
65 |
Correct |
1 ms |
256 KB |
Output is correct |
66 |
Correct |
60 ms |
6776 KB |
Output is correct |
67 |
Correct |
246 ms |
26104 KB |
Output is correct |
68 |
Correct |
251 ms |
26140 KB |
Output is correct |
69 |
Correct |
245 ms |
26104 KB |
Output is correct |
70 |
Correct |
0 ms |
256 KB |
Output is correct |
71 |
Correct |
0 ms |
256 KB |
Output is correct |
72 |
Correct |
1 ms |
256 KB |
Output is correct |
73 |
Correct |
61 ms |
6904 KB |
Output is correct |
74 |
Correct |
241 ms |
26104 KB |
Output is correct |
75 |
Correct |
247 ms |
26104 KB |
Output is correct |
76 |
Correct |
242 ms |
25976 KB |
Output is correct |
77 |
Correct |
238 ms |
26104 KB |
Output is correct |
78 |
Correct |
0 ms |
256 KB |
Output is correct |
79 |
Correct |
0 ms |
256 KB |
Output is correct |
80 |
Correct |
8 ms |
1024 KB |
Output is correct |
81 |
Correct |
123 ms |
16120 KB |
Output is correct |
82 |
Correct |
1 ms |
256 KB |
Output is correct |
83 |
Correct |
0 ms |
256 KB |
Output is correct |
84 |
Correct |
0 ms |
256 KB |
Output is correct |
85 |
Correct |
60 ms |
6776 KB |
Output is correct |
86 |
Correct |
102 ms |
16120 KB |
Output is correct |
87 |
Correct |
106 ms |
16120 KB |
Output is correct |
88 |
Correct |
102 ms |
16120 KB |
Output is correct |
89 |
Correct |
110 ms |
16120 KB |
Output is correct |
90 |
Correct |
0 ms |
256 KB |
Output is correct |
91 |
Correct |
0 ms |
256 KB |
Output is correct |
92 |
Correct |
5 ms |
1024 KB |
Output is correct |
93 |
Correct |
104 ms |
16120 KB |
Output is correct |
94 |
Correct |
1 ms |
256 KB |
Output is correct |
95 |
Correct |
0 ms |
256 KB |
Output is correct |
96 |
Correct |
0 ms |
256 KB |
Output is correct |
97 |
Correct |
26 ms |
4344 KB |
Output is correct |
98 |
Correct |
107 ms |
16248 KB |
Output is correct |
99 |
Correct |
102 ms |
16120 KB |
Output is correct |
100 |
Correct |
101 ms |
16124 KB |
Output is correct |
101 |
Correct |
103 ms |
16084 KB |
Output is correct |
102 |
Correct |
104 ms |
16120 KB |
Output is correct |
103 |
Correct |
103 ms |
16092 KB |
Output is correct |
104 |
Correct |
105 ms |
16152 KB |
Output is correct |
105 |
Correct |
105 ms |
16120 KB |
Output is correct |