/*
{
######################
# Author #
# Gary #
# 2020 #
######################
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define R(a) cin>>a
#define R2(a,b) cin>>a>>b
#define check_min(a,b) a=min(a,b)
#define check_max(a,b) a=max(a,b)
#include "supertrees.h"
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
/*}
*/
const int MAXN=1001;
struct my_dsu{
vector<int> vec[MAXN];
int fa[MAXN];
int root(int u){
return fa[u]=(fa[u]==u? u:root(fa[u]));
}
void merge(int u,int v){
u=root(u);
v=root(v);
if(u==v) return;
if(vec[u].size()>vec[v].size()) swap(u,v);
for(auto it:vec[u])
vec[v].PB(it);
fa[u]=v;
vec[u].clear();
}
}dsu,dsu2;
bool three[MAXN];
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
rep(i,n)
dsu.fa[i]=i,dsu.vec[i].PB(i),dsu2.fa[i]=i,dsu2.vec[i].PB(i);
vector<vector<int> > ans=vector<vector<int> > (n,vector<int> (n,0));
rep(i,n)
rep(j,n){
if(p[i][j]==1){
dsu.merge(i,j);
}
}
rep(i,n)
rep(j,n)
if(dsu.root(i)==dsu.root(j)){
if(p[i][j]!=1) return 0;
}
rep(i,n)
if(dsu.root(i)==i)
{
int las=-1;
for(auto it:dsu.vec[i])
{
if(las!=-1){
ans[las][it]=ans[it][las]=1;
}
las=it;
}
}
// rep(i,n)
// if(dsu.root(i)==i){
// for(auto it:dsu.vec[i]) cout<<it<<' ';
// cout<<endl;
// }
rep(i,n)
rep(j,n)
if(p[i][j]>1){
// cout<<dsu.root(i)<<'_'<<dsu.root(j)<<endl;
dsu2.merge(dsu.root(i),dsu.root(j));
}
rep(i,n)
rep(j,n)
if(dsu.root(i)!=dsu.root(j))
if(dsu2.root(dsu.root(i))==dsu2.root(dsu.root(j))){
if(p[i][j]<=1){
// cout<<'!'<<' '<<i<<" "<<j<<endl;
return false;
}
}
rep(i,n)
if(dsu2.root(i)==i){
if(dsu2.vec[i].size()==1) continue;
if(dsu2.vec[i].size()==2) return 0;
int las=dsu2.vec[i].back();
for(auto it:dsu2.vec[i]){
ans[it][las]=ans[las][it]=1;
las=it;
}
}
// cout<<"TONOW\n";
rep(i,n)
rep(j,n)
if(p[i][j]==3){
three[dsu2.root(dsu.root(i))]=1;
}
rep(i,n)
if(three[i]){
if(dsu2.vec[i].size()<=3) return 0;
ans[dsu2.vec[i][0]][dsu2.vec[i][2]]=ans[dsu2.vec[i][2]][dsu2.vec[i][0]]=1;
}
rep(i,n)
rep(j,n)
if(dsu2.root(dsu.root(i))==dsu2.root(dsu.root(j))){
if(three[dsu2.root(dsu.root(i))]){
if(p[i][j]!=3) return false;
}
}
// for(auto it:ans){
// for(auto itt:it){
// cout<<itt<<' ';
// }
// cout<<endl;
// }
build(ans);
return 1;
}
//int main(){
// fastio;
// cout<<construct({{1,3},{3,1}});
// return 0;
//}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
12 ms |
1408 KB |
Output is correct |
7 |
Correct |
273 ms |
22328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
12 ms |
1408 KB |
Output is correct |
7 |
Correct |
273 ms |
22328 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
11 ms |
1280 KB |
Output is correct |
13 |
Correct |
246 ms |
22264 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
896 KB |
Output is correct |
17 |
Correct |
117 ms |
12280 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
68 ms |
5880 KB |
Output is correct |
21 |
Correct |
272 ms |
22264 KB |
Output is correct |
22 |
Correct |
265 ms |
22328 KB |
Output is correct |
23 |
Correct |
291 ms |
22264 KB |
Output is correct |
24 |
Correct |
247 ms |
22136 KB |
Output is correct |
25 |
Correct |
100 ms |
12280 KB |
Output is correct |
26 |
Correct |
97 ms |
12280 KB |
Output is correct |
27 |
Correct |
289 ms |
22288 KB |
Output is correct |
28 |
Correct |
243 ms |
22264 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
10 ms |
1408 KB |
Output is correct |
9 |
Correct |
247 ms |
22136 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
11 ms |
1280 KB |
Output is correct |
13 |
Correct |
267 ms |
22252 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
896 KB |
Output is correct |
17 |
Correct |
119 ms |
12280 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
512 KB |
Output is correct |
21 |
Correct |
64 ms |
5880 KB |
Output is correct |
22 |
Correct |
255 ms |
22264 KB |
Output is correct |
23 |
Correct |
261 ms |
22520 KB |
Output is correct |
24 |
Correct |
276 ms |
22264 KB |
Output is correct |
25 |
Correct |
106 ms |
12280 KB |
Output is correct |
26 |
Correct |
102 ms |
12280 KB |
Output is correct |
27 |
Correct |
253 ms |
22264 KB |
Output is correct |
28 |
Correct |
278 ms |
22264 KB |
Output is correct |
29 |
Correct |
107 ms |
12408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
67 ms |
5880 KB |
Output is correct |
5 |
Correct |
275 ms |
22264 KB |
Output is correct |
6 |
Correct |
262 ms |
22160 KB |
Output is correct |
7 |
Correct |
290 ms |
22264 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
65 ms |
5880 KB |
Output is correct |
10 |
Correct |
268 ms |
22264 KB |
Output is correct |
11 |
Correct |
255 ms |
22300 KB |
Output is correct |
12 |
Correct |
279 ms |
22264 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
66 ms |
5880 KB |
Output is correct |
17 |
Correct |
255 ms |
22264 KB |
Output is correct |
18 |
Correct |
279 ms |
22264 KB |
Output is correct |
19 |
Correct |
268 ms |
22264 KB |
Output is correct |
20 |
Correct |
248 ms |
22136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
12 ms |
1408 KB |
Output is correct |
7 |
Correct |
273 ms |
22328 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
11 ms |
1280 KB |
Output is correct |
13 |
Correct |
246 ms |
22264 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
896 KB |
Output is correct |
17 |
Correct |
117 ms |
12280 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
68 ms |
5880 KB |
Output is correct |
21 |
Correct |
272 ms |
22264 KB |
Output is correct |
22 |
Correct |
265 ms |
22328 KB |
Output is correct |
23 |
Correct |
291 ms |
22264 KB |
Output is correct |
24 |
Correct |
247 ms |
22136 KB |
Output is correct |
25 |
Correct |
100 ms |
12280 KB |
Output is correct |
26 |
Correct |
97 ms |
12280 KB |
Output is correct |
27 |
Correct |
289 ms |
22288 KB |
Output is correct |
28 |
Correct |
243 ms |
22264 KB |
Output is correct |
29 |
Correct |
0 ms |
384 KB |
Output is correct |
30 |
Correct |
0 ms |
384 KB |
Output is correct |
31 |
Correct |
0 ms |
384 KB |
Output is correct |
32 |
Correct |
0 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
0 ms |
384 KB |
Output is correct |
35 |
Correct |
0 ms |
384 KB |
Output is correct |
36 |
Correct |
10 ms |
1408 KB |
Output is correct |
37 |
Correct |
247 ms |
22136 KB |
Output is correct |
38 |
Correct |
0 ms |
384 KB |
Output is correct |
39 |
Correct |
0 ms |
384 KB |
Output is correct |
40 |
Correct |
11 ms |
1280 KB |
Output is correct |
41 |
Correct |
267 ms |
22252 KB |
Output is correct |
42 |
Correct |
0 ms |
384 KB |
Output is correct |
43 |
Correct |
0 ms |
384 KB |
Output is correct |
44 |
Correct |
5 ms |
896 KB |
Output is correct |
45 |
Correct |
119 ms |
12280 KB |
Output is correct |
46 |
Correct |
1 ms |
384 KB |
Output is correct |
47 |
Correct |
1 ms |
384 KB |
Output is correct |
48 |
Correct |
1 ms |
512 KB |
Output is correct |
49 |
Correct |
64 ms |
5880 KB |
Output is correct |
50 |
Correct |
255 ms |
22264 KB |
Output is correct |
51 |
Correct |
261 ms |
22520 KB |
Output is correct |
52 |
Correct |
276 ms |
22264 KB |
Output is correct |
53 |
Correct |
106 ms |
12280 KB |
Output is correct |
54 |
Correct |
102 ms |
12280 KB |
Output is correct |
55 |
Correct |
253 ms |
22264 KB |
Output is correct |
56 |
Correct |
278 ms |
22264 KB |
Output is correct |
57 |
Correct |
107 ms |
12408 KB |
Output is correct |
58 |
Correct |
0 ms |
384 KB |
Output is correct |
59 |
Correct |
1 ms |
384 KB |
Output is correct |
60 |
Correct |
5 ms |
896 KB |
Output is correct |
61 |
Correct |
116 ms |
12280 KB |
Output is correct |
62 |
Correct |
1 ms |
384 KB |
Output is correct |
63 |
Correct |
0 ms |
384 KB |
Output is correct |
64 |
Correct |
1 ms |
384 KB |
Output is correct |
65 |
Correct |
66 ms |
5880 KB |
Output is correct |
66 |
Correct |
109 ms |
12280 KB |
Output is correct |
67 |
Correct |
100 ms |
12280 KB |
Output is correct |
68 |
Correct |
106 ms |
12308 KB |
Output is correct |
69 |
Correct |
107 ms |
12280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
12 ms |
1408 KB |
Output is correct |
7 |
Correct |
273 ms |
22328 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
11 ms |
1280 KB |
Output is correct |
13 |
Correct |
246 ms |
22264 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
896 KB |
Output is correct |
17 |
Correct |
117 ms |
12280 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
68 ms |
5880 KB |
Output is correct |
21 |
Correct |
272 ms |
22264 KB |
Output is correct |
22 |
Correct |
265 ms |
22328 KB |
Output is correct |
23 |
Correct |
291 ms |
22264 KB |
Output is correct |
24 |
Correct |
247 ms |
22136 KB |
Output is correct |
25 |
Correct |
100 ms |
12280 KB |
Output is correct |
26 |
Correct |
97 ms |
12280 KB |
Output is correct |
27 |
Correct |
289 ms |
22288 KB |
Output is correct |
28 |
Correct |
243 ms |
22264 KB |
Output is correct |
29 |
Correct |
0 ms |
384 KB |
Output is correct |
30 |
Correct |
0 ms |
384 KB |
Output is correct |
31 |
Correct |
0 ms |
384 KB |
Output is correct |
32 |
Correct |
0 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
0 ms |
384 KB |
Output is correct |
35 |
Correct |
0 ms |
384 KB |
Output is correct |
36 |
Correct |
10 ms |
1408 KB |
Output is correct |
37 |
Correct |
247 ms |
22136 KB |
Output is correct |
38 |
Correct |
0 ms |
384 KB |
Output is correct |
39 |
Correct |
0 ms |
384 KB |
Output is correct |
40 |
Correct |
11 ms |
1280 KB |
Output is correct |
41 |
Correct |
267 ms |
22252 KB |
Output is correct |
42 |
Correct |
0 ms |
384 KB |
Output is correct |
43 |
Correct |
0 ms |
384 KB |
Output is correct |
44 |
Correct |
5 ms |
896 KB |
Output is correct |
45 |
Correct |
119 ms |
12280 KB |
Output is correct |
46 |
Correct |
1 ms |
384 KB |
Output is correct |
47 |
Correct |
1 ms |
384 KB |
Output is correct |
48 |
Correct |
1 ms |
512 KB |
Output is correct |
49 |
Correct |
64 ms |
5880 KB |
Output is correct |
50 |
Correct |
255 ms |
22264 KB |
Output is correct |
51 |
Correct |
261 ms |
22520 KB |
Output is correct |
52 |
Correct |
276 ms |
22264 KB |
Output is correct |
53 |
Correct |
106 ms |
12280 KB |
Output is correct |
54 |
Correct |
102 ms |
12280 KB |
Output is correct |
55 |
Correct |
253 ms |
22264 KB |
Output is correct |
56 |
Correct |
278 ms |
22264 KB |
Output is correct |
57 |
Correct |
107 ms |
12408 KB |
Output is correct |
58 |
Correct |
1 ms |
384 KB |
Output is correct |
59 |
Correct |
1 ms |
384 KB |
Output is correct |
60 |
Correct |
1 ms |
384 KB |
Output is correct |
61 |
Correct |
67 ms |
5880 KB |
Output is correct |
62 |
Correct |
275 ms |
22264 KB |
Output is correct |
63 |
Correct |
262 ms |
22160 KB |
Output is correct |
64 |
Correct |
290 ms |
22264 KB |
Output is correct |
65 |
Correct |
1 ms |
384 KB |
Output is correct |
66 |
Correct |
65 ms |
5880 KB |
Output is correct |
67 |
Correct |
268 ms |
22264 KB |
Output is correct |
68 |
Correct |
255 ms |
22300 KB |
Output is correct |
69 |
Correct |
279 ms |
22264 KB |
Output is correct |
70 |
Correct |
1 ms |
384 KB |
Output is correct |
71 |
Correct |
1 ms |
384 KB |
Output is correct |
72 |
Correct |
1 ms |
384 KB |
Output is correct |
73 |
Correct |
66 ms |
5880 KB |
Output is correct |
74 |
Correct |
255 ms |
22264 KB |
Output is correct |
75 |
Correct |
279 ms |
22264 KB |
Output is correct |
76 |
Correct |
268 ms |
22264 KB |
Output is correct |
77 |
Correct |
248 ms |
22136 KB |
Output is correct |
78 |
Correct |
0 ms |
384 KB |
Output is correct |
79 |
Correct |
1 ms |
384 KB |
Output is correct |
80 |
Correct |
5 ms |
896 KB |
Output is correct |
81 |
Correct |
116 ms |
12280 KB |
Output is correct |
82 |
Correct |
1 ms |
384 KB |
Output is correct |
83 |
Correct |
0 ms |
384 KB |
Output is correct |
84 |
Correct |
1 ms |
384 KB |
Output is correct |
85 |
Correct |
66 ms |
5880 KB |
Output is correct |
86 |
Correct |
109 ms |
12280 KB |
Output is correct |
87 |
Correct |
100 ms |
12280 KB |
Output is correct |
88 |
Correct |
106 ms |
12308 KB |
Output is correct |
89 |
Correct |
107 ms |
12280 KB |
Output is correct |
90 |
Correct |
0 ms |
384 KB |
Output is correct |
91 |
Correct |
1 ms |
384 KB |
Output is correct |
92 |
Correct |
5 ms |
896 KB |
Output is correct |
93 |
Correct |
106 ms |
12312 KB |
Output is correct |
94 |
Correct |
1 ms |
384 KB |
Output is correct |
95 |
Correct |
0 ms |
384 KB |
Output is correct |
96 |
Correct |
0 ms |
384 KB |
Output is correct |
97 |
Correct |
28 ms |
3320 KB |
Output is correct |
98 |
Correct |
105 ms |
12408 KB |
Output is correct |
99 |
Correct |
109 ms |
12280 KB |
Output is correct |
100 |
Correct |
106 ms |
12280 KB |
Output is correct |
101 |
Correct |
107 ms |
12304 KB |
Output is correct |
102 |
Correct |
122 ms |
12408 KB |
Output is correct |
103 |
Correct |
126 ms |
12280 KB |
Output is correct |
104 |
Correct |
109 ms |
12280 KB |
Output is correct |
105 |
Correct |
117 ms |
12280 KB |
Output is correct |