#include "supertrees.h"
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(int)(n);i++)
using namespace std;
struct UnionFind{
vector<int>par;
UnionFind(int n){
par=vector<int>(n);
rep(i,n)par[i]=i;
}
int find(int x){
return par[x]==x?x:par[x]=find(par[x]);
}
void unite(int x,int y){
x=find(x);y=find(y);
par[y]=x;
}
bool same(int x,int y){
return find(x)==find(y);
}
};
static vector<int>v[2000],v2[2000];
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
std::vector<std::vector<int>> answer;
for (int i = 0; i < n; i++) {
std::vector<int> row;
row.resize(n);
answer.push_back(row);
}
UnionFind uf1(n);
rep(i,n)rep(j,n){
if(p[i][j]==1)uf1.unite(i,j);
}
rep(i,n){
v[uf1.find(i)].push_back(i);
}
UnionFind uf2(n);
rep(i,n)for(int j=i+1;j<n;j++){
if(!v[i].empty()&&!v[j].empty()&&p[i][j]==2){
uf2.unite(i,j);
}
}
rep(i,n){
if(!v[i].empty())v2[uf2.find(i)].push_back(i);
}
rep(i,n){
if(v2[i].size()>1){
if(v2[i].size()==2)return 0;
rep(j,v2[i].size()){
answer[v2[i][j]][v2[i][(j+1)%v2[i].size()]]=1;
answer[v2[i][(j+1)%v2[i].size()]][v2[i][j]]=1;
}
}
}
rep(i,n){
if(v[i].size()>1){
rep(j,v[i].size()-1){
answer[v[i][j]][v[i][j+1]]=1;
answer[v[i][j+1]][v[i][j]]=1;
}
}
}
rep(i,n)for(int j=i+1;j<n;j++){
if(uf1.same(i,j)){
if(p[i][j]!=1)return 0;
}
else if(uf2.same(uf1.find(i),uf1.find(j))){
if(p[i][j]!=2)return 0;
}
else if(p[i][j]!=0)return 0;
}
build(answer);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
11 ms |
1260 KB |
Output is correct |
7 |
Correct |
255 ms |
22252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
11 ms |
1260 KB |
Output is correct |
7 |
Correct |
255 ms |
22252 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
11 ms |
1260 KB |
Output is correct |
13 |
Correct |
255 ms |
22252 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
5 ms |
876 KB |
Output is correct |
17 |
Correct |
119 ms |
12908 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
65 ms |
5868 KB |
Output is correct |
21 |
Correct |
260 ms |
22464 KB |
Output is correct |
22 |
Correct |
253 ms |
22252 KB |
Output is correct |
23 |
Correct |
267 ms |
22252 KB |
Output is correct |
24 |
Correct |
257 ms |
22252 KB |
Output is correct |
25 |
Correct |
106 ms |
13036 KB |
Output is correct |
26 |
Correct |
105 ms |
13292 KB |
Output is correct |
27 |
Correct |
265 ms |
22252 KB |
Output is correct |
28 |
Correct |
254 ms |
22208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
11 ms |
1260 KB |
Output is correct |
9 |
Correct |
252 ms |
22252 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
11 ms |
1388 KB |
Output is correct |
13 |
Correct |
249 ms |
22380 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
5 ms |
876 KB |
Output is correct |
17 |
Correct |
110 ms |
12268 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
68 ms |
5996 KB |
Output is correct |
22 |
Correct |
257 ms |
22252 KB |
Output is correct |
23 |
Correct |
260 ms |
22380 KB |
Output is correct |
24 |
Correct |
262 ms |
22252 KB |
Output is correct |
25 |
Correct |
110 ms |
12268 KB |
Output is correct |
26 |
Correct |
109 ms |
12268 KB |
Output is correct |
27 |
Correct |
257 ms |
22252 KB |
Output is correct |
28 |
Correct |
273 ms |
22252 KB |
Output is correct |
29 |
Correct |
105 ms |
12268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
68 ms |
5868 KB |
Output is correct |
5 |
Correct |
260 ms |
22380 KB |
Output is correct |
6 |
Correct |
255 ms |
22252 KB |
Output is correct |
7 |
Correct |
281 ms |
22252 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
64 ms |
5996 KB |
Output is correct |
10 |
Correct |
261 ms |
22380 KB |
Output is correct |
11 |
Correct |
259 ms |
22252 KB |
Output is correct |
12 |
Correct |
261 ms |
22252 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
65 ms |
5996 KB |
Output is correct |
17 |
Correct |
254 ms |
22252 KB |
Output is correct |
18 |
Correct |
260 ms |
22252 KB |
Output is correct |
19 |
Correct |
259 ms |
22424 KB |
Output is correct |
20 |
Correct |
255 ms |
22380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
11 ms |
1260 KB |
Output is correct |
7 |
Correct |
255 ms |
22252 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
11 ms |
1260 KB |
Output is correct |
13 |
Correct |
255 ms |
22252 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
5 ms |
876 KB |
Output is correct |
17 |
Correct |
119 ms |
12908 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
65 ms |
5868 KB |
Output is correct |
21 |
Correct |
260 ms |
22464 KB |
Output is correct |
22 |
Correct |
253 ms |
22252 KB |
Output is correct |
23 |
Correct |
267 ms |
22252 KB |
Output is correct |
24 |
Correct |
257 ms |
22252 KB |
Output is correct |
25 |
Correct |
106 ms |
13036 KB |
Output is correct |
26 |
Correct |
105 ms |
13292 KB |
Output is correct |
27 |
Correct |
265 ms |
22252 KB |
Output is correct |
28 |
Correct |
254 ms |
22208 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
492 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
11 ms |
1260 KB |
Output is correct |
37 |
Correct |
252 ms |
22252 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
1 ms |
364 KB |
Output is correct |
40 |
Correct |
11 ms |
1388 KB |
Output is correct |
41 |
Correct |
249 ms |
22380 KB |
Output is correct |
42 |
Correct |
1 ms |
364 KB |
Output is correct |
43 |
Correct |
1 ms |
364 KB |
Output is correct |
44 |
Correct |
5 ms |
876 KB |
Output is correct |
45 |
Correct |
110 ms |
12268 KB |
Output is correct |
46 |
Correct |
1 ms |
364 KB |
Output is correct |
47 |
Correct |
1 ms |
364 KB |
Output is correct |
48 |
Correct |
1 ms |
364 KB |
Output is correct |
49 |
Correct |
68 ms |
5996 KB |
Output is correct |
50 |
Correct |
257 ms |
22252 KB |
Output is correct |
51 |
Correct |
260 ms |
22380 KB |
Output is correct |
52 |
Correct |
262 ms |
22252 KB |
Output is correct |
53 |
Correct |
110 ms |
12268 KB |
Output is correct |
54 |
Correct |
109 ms |
12268 KB |
Output is correct |
55 |
Correct |
257 ms |
22252 KB |
Output is correct |
56 |
Correct |
273 ms |
22252 KB |
Output is correct |
57 |
Correct |
105 ms |
12268 KB |
Output is correct |
58 |
Correct |
1 ms |
364 KB |
Output is correct |
59 |
Correct |
1 ms |
364 KB |
Output is correct |
60 |
Correct |
5 ms |
1004 KB |
Output is correct |
61 |
Correct |
111 ms |
14188 KB |
Output is correct |
62 |
Correct |
1 ms |
364 KB |
Output is correct |
63 |
Correct |
1 ms |
364 KB |
Output is correct |
64 |
Correct |
1 ms |
364 KB |
Output is correct |
65 |
Correct |
67 ms |
6380 KB |
Output is correct |
66 |
Correct |
112 ms |
14316 KB |
Output is correct |
67 |
Correct |
116 ms |
14336 KB |
Output is correct |
68 |
Correct |
108 ms |
14444 KB |
Output is correct |
69 |
Correct |
112 ms |
14316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
11 ms |
1260 KB |
Output is correct |
7 |
Correct |
255 ms |
22252 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
11 ms |
1260 KB |
Output is correct |
13 |
Correct |
255 ms |
22252 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
5 ms |
876 KB |
Output is correct |
17 |
Correct |
119 ms |
12908 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
65 ms |
5868 KB |
Output is correct |
21 |
Correct |
260 ms |
22464 KB |
Output is correct |
22 |
Correct |
253 ms |
22252 KB |
Output is correct |
23 |
Correct |
267 ms |
22252 KB |
Output is correct |
24 |
Correct |
257 ms |
22252 KB |
Output is correct |
25 |
Correct |
106 ms |
13036 KB |
Output is correct |
26 |
Correct |
105 ms |
13292 KB |
Output is correct |
27 |
Correct |
265 ms |
22252 KB |
Output is correct |
28 |
Correct |
254 ms |
22208 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
492 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
364 KB |
Output is correct |
35 |
Correct |
1 ms |
364 KB |
Output is correct |
36 |
Correct |
11 ms |
1260 KB |
Output is correct |
37 |
Correct |
252 ms |
22252 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
1 ms |
364 KB |
Output is correct |
40 |
Correct |
11 ms |
1388 KB |
Output is correct |
41 |
Correct |
249 ms |
22380 KB |
Output is correct |
42 |
Correct |
1 ms |
364 KB |
Output is correct |
43 |
Correct |
1 ms |
364 KB |
Output is correct |
44 |
Correct |
5 ms |
876 KB |
Output is correct |
45 |
Correct |
110 ms |
12268 KB |
Output is correct |
46 |
Correct |
1 ms |
364 KB |
Output is correct |
47 |
Correct |
1 ms |
364 KB |
Output is correct |
48 |
Correct |
1 ms |
364 KB |
Output is correct |
49 |
Correct |
68 ms |
5996 KB |
Output is correct |
50 |
Correct |
257 ms |
22252 KB |
Output is correct |
51 |
Correct |
260 ms |
22380 KB |
Output is correct |
52 |
Correct |
262 ms |
22252 KB |
Output is correct |
53 |
Correct |
110 ms |
12268 KB |
Output is correct |
54 |
Correct |
109 ms |
12268 KB |
Output is correct |
55 |
Correct |
257 ms |
22252 KB |
Output is correct |
56 |
Correct |
273 ms |
22252 KB |
Output is correct |
57 |
Correct |
105 ms |
12268 KB |
Output is correct |
58 |
Correct |
1 ms |
364 KB |
Output is correct |
59 |
Correct |
1 ms |
364 KB |
Output is correct |
60 |
Correct |
1 ms |
364 KB |
Output is correct |
61 |
Correct |
68 ms |
5868 KB |
Output is correct |
62 |
Correct |
260 ms |
22380 KB |
Output is correct |
63 |
Correct |
255 ms |
22252 KB |
Output is correct |
64 |
Correct |
281 ms |
22252 KB |
Output is correct |
65 |
Correct |
1 ms |
364 KB |
Output is correct |
66 |
Correct |
64 ms |
5996 KB |
Output is correct |
67 |
Correct |
261 ms |
22380 KB |
Output is correct |
68 |
Correct |
259 ms |
22252 KB |
Output is correct |
69 |
Correct |
261 ms |
22252 KB |
Output is correct |
70 |
Correct |
1 ms |
364 KB |
Output is correct |
71 |
Correct |
1 ms |
364 KB |
Output is correct |
72 |
Correct |
1 ms |
364 KB |
Output is correct |
73 |
Correct |
65 ms |
5996 KB |
Output is correct |
74 |
Correct |
254 ms |
22252 KB |
Output is correct |
75 |
Correct |
260 ms |
22252 KB |
Output is correct |
76 |
Correct |
259 ms |
22424 KB |
Output is correct |
77 |
Correct |
255 ms |
22380 KB |
Output is correct |
78 |
Correct |
1 ms |
364 KB |
Output is correct |
79 |
Correct |
1 ms |
364 KB |
Output is correct |
80 |
Correct |
5 ms |
1004 KB |
Output is correct |
81 |
Correct |
111 ms |
14188 KB |
Output is correct |
82 |
Correct |
1 ms |
364 KB |
Output is correct |
83 |
Correct |
1 ms |
364 KB |
Output is correct |
84 |
Correct |
1 ms |
364 KB |
Output is correct |
85 |
Correct |
67 ms |
6380 KB |
Output is correct |
86 |
Correct |
112 ms |
14316 KB |
Output is correct |
87 |
Correct |
116 ms |
14336 KB |
Output is correct |
88 |
Correct |
108 ms |
14444 KB |
Output is correct |
89 |
Correct |
112 ms |
14316 KB |
Output is correct |
90 |
Correct |
1 ms |
364 KB |
Output is correct |
91 |
Correct |
1 ms |
364 KB |
Output is correct |
92 |
Correct |
5 ms |
1004 KB |
Output is correct |
93 |
Correct |
117 ms |
14188 KB |
Output is correct |
94 |
Correct |
1 ms |
364 KB |
Output is correct |
95 |
Correct |
1 ms |
364 KB |
Output is correct |
96 |
Correct |
1 ms |
364 KB |
Output is correct |
97 |
Correct |
28 ms |
3948 KB |
Output is correct |
98 |
Correct |
116 ms |
14316 KB |
Output is correct |
99 |
Correct |
111 ms |
14316 KB |
Output is correct |
100 |
Correct |
108 ms |
14316 KB |
Output is correct |
101 |
Correct |
110 ms |
14316 KB |
Output is correct |
102 |
Correct |
96 ms |
14316 KB |
Output is correct |
103 |
Correct |
101 ms |
14316 KB |
Output is correct |
104 |
Correct |
114 ms |
14188 KB |
Output is correct |
105 |
Correct |
107 ms |
14444 KB |
Output is correct |