#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
typedef pair<int,int> pii;
int construct(vector<vector<int>> p) {
int N=p.size();
vector<pii> comps(N);
for(int i=0;i<N;++i) comps[i]={-1,-1};
int newcomp=0;
vector<int> newsubcomp(N,0);
for(int i=0;i<N;++i) {
if(comps[i]==pii(-1,-1)) {
comps[i]={newcomp,newsubcomp[newcomp]++};
newcomp++;
}
else if(comps[i].second<0) comps[i].second=newsubcomp[comps[i].first]++;
for(int j=i+1;j<N;++j) {
if(p[i][j]==3) return 0;
if(comps[j]==pii(-1,-1)) {
if(p[i][j]==0) continue;
if(p[i][j]==1) comps[j]=comps[i];
if(p[i][j]==2) comps[j].first=comps[i].first;
} else {
if(p[i][j]==0&&comps[i].first==comps[j].first) return 0;
if(p[i][j]==1) {
if(comps[i].second!=comps[j].second) {
if(comps[j].second>=0) return 0;
else comps[j].second=comps[i].second;
}
}
if(p[i][j]==2&&(comps[i]==comps[j]||comps[i].first!=comps[j].first)) return 0;
}
}
}
for(int i=0;i<N;++i) for(int j=i+1;j<N;++j) {
if(p[i][j]==0&&comps[i].first==comps[j].first) return 0;
if(p[i][j]==1&&(comps[i].first!=comps[j].first||(comps[i].second!=comps[j].second&&comps[j].second>=0))) return 0;
if(p[i][j]==2&&(comps[i]==comps[j]||comps[i].first!=comps[j].first)) return 0;
}
vector<vector<vector<int>>> gr(N,vector<vector<int>>(N));
int i=0;
for(pii p:comps) gr[p.first][p.second].push_back(i++);
vector<vector<int>> ans(N,vector<int>(N,0));
for(int i=0;i<newcomp;++i) {
if(newsubcomp[i]==2) return 0;
for(int j=0;j<newsubcomp[i];++j) {
for(int k=1;k<(int)gr[i][j].size();++k) ans[gr[i][j][k]][gr[i][j][0]]=ans[gr[i][j][0]][gr[i][j][k]]=1;
if(j==0) ans[gr[i][j][0]][gr[i][newsubcomp[i]-1][0]]=ans[gr[i][newsubcomp[i]-1][0]][gr[i][j][0]]=1;
else ans[gr[i][j][0]][gr[i][j-1][0]]=ans[gr[i][j-1][0]][gr[i][j][0]]=1;
}
}
for(int i=0;i<N;++i) ans[i][i]=0;
build(ans);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
9 ms |
2132 KB |
Output is correct |
7 |
Correct |
184 ms |
45588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
9 ms |
2132 KB |
Output is correct |
7 |
Correct |
184 ms |
45588 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
2132 KB |
Output is correct |
13 |
Correct |
191 ms |
45516 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
596 KB |
Output is correct |
17 |
Correct |
69 ms |
8080 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
59 ms |
11612 KB |
Output is correct |
21 |
Correct |
185 ms |
45520 KB |
Output is correct |
22 |
Correct |
177 ms |
45584 KB |
Output is correct |
23 |
Correct |
188 ms |
45568 KB |
Output is correct |
24 |
Correct |
179 ms |
45572 KB |
Output is correct |
25 |
Correct |
65 ms |
8156 KB |
Output is correct |
26 |
Correct |
64 ms |
8140 KB |
Output is correct |
27 |
Correct |
184 ms |
45580 KB |
Output is correct |
28 |
Correct |
177 ms |
45572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
300 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
9 ms |
2132 KB |
Output is correct |
9 |
Correct |
192 ms |
47548 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
292 KB |
Output is correct |
12 |
Correct |
8 ms |
2132 KB |
Output is correct |
13 |
Correct |
179 ms |
47568 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
300 KB |
Output is correct |
16 |
Correct |
4 ms |
596 KB |
Output is correct |
17 |
Correct |
76 ms |
10112 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
296 KB |
Output is correct |
21 |
Correct |
49 ms |
12156 KB |
Output is correct |
22 |
Correct |
182 ms |
47560 KB |
Output is correct |
23 |
Correct |
186 ms |
47564 KB |
Output is correct |
24 |
Correct |
184 ms |
47504 KB |
Output is correct |
25 |
Correct |
109 ms |
37632 KB |
Output is correct |
26 |
Correct |
68 ms |
10060 KB |
Output is correct |
27 |
Correct |
176 ms |
47488 KB |
Output is correct |
28 |
Correct |
194 ms |
47480 KB |
Output is correct |
29 |
Correct |
94 ms |
37620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
47 ms |
11572 KB |
Output is correct |
5 |
Correct |
178 ms |
45568 KB |
Output is correct |
6 |
Correct |
206 ms |
45572 KB |
Output is correct |
7 |
Correct |
184 ms |
45600 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
52 ms |
11596 KB |
Output is correct |
10 |
Correct |
183 ms |
45516 KB |
Output is correct |
11 |
Correct |
213 ms |
45592 KB |
Output is correct |
12 |
Correct |
205 ms |
45596 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
45 ms |
11640 KB |
Output is correct |
17 |
Correct |
189 ms |
45524 KB |
Output is correct |
18 |
Correct |
179 ms |
45588 KB |
Output is correct |
19 |
Correct |
188 ms |
45632 KB |
Output is correct |
20 |
Correct |
181 ms |
45564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
9 ms |
2132 KB |
Output is correct |
7 |
Correct |
184 ms |
45588 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
2132 KB |
Output is correct |
13 |
Correct |
191 ms |
45516 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
596 KB |
Output is correct |
17 |
Correct |
69 ms |
8080 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
59 ms |
11612 KB |
Output is correct |
21 |
Correct |
185 ms |
45520 KB |
Output is correct |
22 |
Correct |
177 ms |
45584 KB |
Output is correct |
23 |
Correct |
188 ms |
45568 KB |
Output is correct |
24 |
Correct |
179 ms |
45572 KB |
Output is correct |
25 |
Correct |
65 ms |
8156 KB |
Output is correct |
26 |
Correct |
64 ms |
8140 KB |
Output is correct |
27 |
Correct |
184 ms |
45580 KB |
Output is correct |
28 |
Correct |
177 ms |
45572 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
300 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
9 ms |
2132 KB |
Output is correct |
37 |
Correct |
192 ms |
47548 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
292 KB |
Output is correct |
40 |
Correct |
8 ms |
2132 KB |
Output is correct |
41 |
Correct |
179 ms |
47568 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
300 KB |
Output is correct |
44 |
Correct |
4 ms |
596 KB |
Output is correct |
45 |
Correct |
76 ms |
10112 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
296 KB |
Output is correct |
49 |
Correct |
49 ms |
12156 KB |
Output is correct |
50 |
Correct |
182 ms |
47560 KB |
Output is correct |
51 |
Correct |
186 ms |
47564 KB |
Output is correct |
52 |
Correct |
184 ms |
47504 KB |
Output is correct |
53 |
Correct |
109 ms |
37632 KB |
Output is correct |
54 |
Correct |
68 ms |
10060 KB |
Output is correct |
55 |
Correct |
176 ms |
47488 KB |
Output is correct |
56 |
Correct |
194 ms |
47480 KB |
Output is correct |
57 |
Correct |
94 ms |
37620 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
340 KB |
Output is correct |
60 |
Correct |
4 ms |
596 KB |
Output is correct |
61 |
Correct |
69 ms |
10108 KB |
Output is correct |
62 |
Correct |
1 ms |
212 KB |
Output is correct |
63 |
Correct |
1 ms |
212 KB |
Output is correct |
64 |
Correct |
1 ms |
212 KB |
Output is correct |
65 |
Correct |
50 ms |
12092 KB |
Output is correct |
66 |
Correct |
72 ms |
10096 KB |
Output is correct |
67 |
Correct |
71 ms |
10104 KB |
Output is correct |
68 |
Correct |
87 ms |
10116 KB |
Output is correct |
69 |
Correct |
92 ms |
37628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
9 ms |
2132 KB |
Output is correct |
7 |
Correct |
184 ms |
45588 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
2132 KB |
Output is correct |
13 |
Correct |
191 ms |
45516 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
596 KB |
Output is correct |
17 |
Correct |
69 ms |
8080 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
59 ms |
11612 KB |
Output is correct |
21 |
Correct |
185 ms |
45520 KB |
Output is correct |
22 |
Correct |
177 ms |
45584 KB |
Output is correct |
23 |
Correct |
188 ms |
45568 KB |
Output is correct |
24 |
Correct |
179 ms |
45572 KB |
Output is correct |
25 |
Correct |
65 ms |
8156 KB |
Output is correct |
26 |
Correct |
64 ms |
8140 KB |
Output is correct |
27 |
Correct |
184 ms |
45580 KB |
Output is correct |
28 |
Correct |
177 ms |
45572 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
300 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
9 ms |
2132 KB |
Output is correct |
37 |
Correct |
192 ms |
47548 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
292 KB |
Output is correct |
40 |
Correct |
8 ms |
2132 KB |
Output is correct |
41 |
Correct |
179 ms |
47568 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
300 KB |
Output is correct |
44 |
Correct |
4 ms |
596 KB |
Output is correct |
45 |
Correct |
76 ms |
10112 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
296 KB |
Output is correct |
49 |
Correct |
49 ms |
12156 KB |
Output is correct |
50 |
Correct |
182 ms |
47560 KB |
Output is correct |
51 |
Correct |
186 ms |
47564 KB |
Output is correct |
52 |
Correct |
184 ms |
47504 KB |
Output is correct |
53 |
Correct |
109 ms |
37632 KB |
Output is correct |
54 |
Correct |
68 ms |
10060 KB |
Output is correct |
55 |
Correct |
176 ms |
47488 KB |
Output is correct |
56 |
Correct |
194 ms |
47480 KB |
Output is correct |
57 |
Correct |
94 ms |
37620 KB |
Output is correct |
58 |
Correct |
0 ms |
212 KB |
Output is correct |
59 |
Correct |
0 ms |
212 KB |
Output is correct |
60 |
Correct |
0 ms |
212 KB |
Output is correct |
61 |
Correct |
47 ms |
11572 KB |
Output is correct |
62 |
Correct |
178 ms |
45568 KB |
Output is correct |
63 |
Correct |
206 ms |
45572 KB |
Output is correct |
64 |
Correct |
184 ms |
45600 KB |
Output is correct |
65 |
Correct |
1 ms |
212 KB |
Output is correct |
66 |
Correct |
52 ms |
11596 KB |
Output is correct |
67 |
Correct |
183 ms |
45516 KB |
Output is correct |
68 |
Correct |
213 ms |
45592 KB |
Output is correct |
69 |
Correct |
205 ms |
45596 KB |
Output is correct |
70 |
Correct |
0 ms |
212 KB |
Output is correct |
71 |
Correct |
0 ms |
212 KB |
Output is correct |
72 |
Correct |
0 ms |
212 KB |
Output is correct |
73 |
Correct |
45 ms |
11640 KB |
Output is correct |
74 |
Correct |
189 ms |
45524 KB |
Output is correct |
75 |
Correct |
179 ms |
45588 KB |
Output is correct |
76 |
Correct |
188 ms |
45632 KB |
Output is correct |
77 |
Correct |
181 ms |
45564 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
1 ms |
340 KB |
Output is correct |
80 |
Correct |
4 ms |
596 KB |
Output is correct |
81 |
Correct |
69 ms |
10108 KB |
Output is correct |
82 |
Correct |
1 ms |
212 KB |
Output is correct |
83 |
Correct |
1 ms |
212 KB |
Output is correct |
84 |
Correct |
1 ms |
212 KB |
Output is correct |
85 |
Correct |
50 ms |
12092 KB |
Output is correct |
86 |
Correct |
72 ms |
10096 KB |
Output is correct |
87 |
Correct |
71 ms |
10104 KB |
Output is correct |
88 |
Correct |
87 ms |
10116 KB |
Output is correct |
89 |
Correct |
92 ms |
37628 KB |
Output is correct |
90 |
Correct |
1 ms |
212 KB |
Output is correct |
91 |
Correct |
1 ms |
280 KB |
Output is correct |
92 |
Correct |
4 ms |
648 KB |
Output is correct |
93 |
Correct |
87 ms |
10100 KB |
Output is correct |
94 |
Correct |
1 ms |
252 KB |
Output is correct |
95 |
Correct |
1 ms |
296 KB |
Output is correct |
96 |
Correct |
1 ms |
212 KB |
Output is correct |
97 |
Correct |
24 ms |
2668 KB |
Output is correct |
98 |
Correct |
74 ms |
10096 KB |
Output is correct |
99 |
Correct |
65 ms |
10100 KB |
Output is correct |
100 |
Correct |
64 ms |
10060 KB |
Output is correct |
101 |
Correct |
64 ms |
10100 KB |
Output is correct |
102 |
Correct |
71 ms |
10028 KB |
Output is correct |
103 |
Correct |
75 ms |
10108 KB |
Output is correct |
104 |
Correct |
69 ms |
10100 KB |
Output is correct |
105 |
Correct |
73 ms |
10068 KB |
Output is correct |