#include "supertrees.h"
#include <cassert>
#include <map>
#include <vector>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define ln "\n"
#define pll pair<ll, ll>
struct DSU{
vector<int> p;
int n, cnt;
DSU(int N){
n=N;
cnt=n;
p.resize(n, -1);
}
int get(int x){
return p[x]==-1?x:p[x]=get(p[x]);
}
bool unite(int a, int b){
a=get(a);
b=get(b);
if (a==b) return 0;
cnt--;
if (a<b) swap(a, b);
p[a]=b;
return 1;
}
};
int construct(std::vector<std::vector<int>> p) {
int n = (int)p.size();
DSU tr(n), tr2(n);
vector<vector<int>> A(n);
for (int i=0; i<n; i++){
for (int j=0; j<n; j++){
if (i!=j and p[i][j]){
tr.unite(i, j);
if (p[i][j]==1) tr2.unite(i, j);
}
}
}
map<int, vector<int>> ccs;
for (int i=0; i<n; i++){
// assert(tr.get(i)<tr.cnt);
ccs[tr.get(i)].push_back(i);
}
vector<vector<int>> ans(n, vector<int>(n));
vector<vector<int>> shadow(n, vector<int>(n));
for (auto &[_, arr]:ccs){
map<int, vector<int>> groups;
for (auto ch:arr){
groups[tr2.get(ch)].push_back(ch);
}
for (ll j=0; j<(int)(arr.size()); j++){
for (ll k=j+1; k<(int)(arr.size()); k++){
shadow[arr[j]][arr[k]]=shadow[arr[k]][arr[j]]=2;
}
}
vector<int> circle;
for (auto &[icc,mem]:groups){
for (ll j=1; j<(int)mem.size(); j++){
ans[mem[j]][mem[j-1]]=ans[mem[j-1]][mem[j]]=1;
}
for (ll j=0; j<(int)mem.size(); j++){
for (ll k=j+1; k<(int)mem.size(); k++){
shadow[mem[j]][mem[k]]=shadow[mem[k]][mem[j]]=1;
}
}
circle.push_back(mem[0]);
}
if (circle.size()==1) continue;
if (circle.size()==2){
return 0;
}
for (ll j=0; j<(int)circle.size(); j++){
int nxt = (j+1)%(int)(circle.size());
ans[circle[j]][circle[nxt]]=ans[circle[nxt]][circle[j]]=1;
}
}
for (ll i=0; i<n; i++){
for (ll j=0; j<n; j++){
if ((i!=j and p[i][j]!=shadow[i][j]) or p[i][j]==3){
return 0;
}
}
}
build(ans);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
10 ms |
1464 KB |
Output is correct |
7 |
Correct |
125 ms |
25960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
10 ms |
1464 KB |
Output is correct |
7 |
Correct |
125 ms |
25960 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
1372 KB |
Output is correct |
13 |
Correct |
121 ms |
26012 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
860 KB |
Output is correct |
17 |
Correct |
69 ms |
16140 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
30 ms |
6688 KB |
Output is correct |
21 |
Correct |
135 ms |
26116 KB |
Output is correct |
22 |
Correct |
111 ms |
26108 KB |
Output is correct |
23 |
Correct |
122 ms |
25936 KB |
Output is correct |
24 |
Correct |
122 ms |
26192 KB |
Output is correct |
25 |
Correct |
57 ms |
16120 KB |
Output is correct |
26 |
Correct |
95 ms |
16208 KB |
Output is correct |
27 |
Correct |
143 ms |
26124 KB |
Output is correct |
28 |
Correct |
116 ms |
26124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
5 ms |
1372 KB |
Output is correct |
9 |
Correct |
150 ms |
28156 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
1456 KB |
Output is correct |
13 |
Correct |
131 ms |
28068 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
1168 KB |
Output is correct |
17 |
Correct |
65 ms |
18256 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
29 ms |
7236 KB |
Output is correct |
22 |
Correct |
120 ms |
28016 KB |
Output is correct |
23 |
Correct |
141 ms |
27984 KB |
Output is correct |
24 |
Correct |
132 ms |
27892 KB |
Output is correct |
25 |
Correct |
96 ms |
18256 KB |
Output is correct |
26 |
Correct |
56 ms |
18000 KB |
Output is correct |
27 |
Correct |
159 ms |
28132 KB |
Output is correct |
28 |
Correct |
124 ms |
27884 KB |
Output is correct |
29 |
Correct |
69 ms |
18172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
49 ms |
6744 KB |
Output is correct |
5 |
Correct |
126 ms |
25996 KB |
Output is correct |
6 |
Correct |
155 ms |
26196 KB |
Output is correct |
7 |
Correct |
137 ms |
26120 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
55 ms |
6812 KB |
Output is correct |
10 |
Correct |
134 ms |
26124 KB |
Output is correct |
11 |
Correct |
145 ms |
25936 KB |
Output is correct |
12 |
Correct |
122 ms |
25936 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
26 ms |
6796 KB |
Output is correct |
17 |
Correct |
106 ms |
26020 KB |
Output is correct |
18 |
Correct |
121 ms |
25936 KB |
Output is correct |
19 |
Correct |
110 ms |
25940 KB |
Output is correct |
20 |
Correct |
128 ms |
26192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
10 ms |
1464 KB |
Output is correct |
7 |
Correct |
125 ms |
25960 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
1372 KB |
Output is correct |
13 |
Correct |
121 ms |
26012 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
860 KB |
Output is correct |
17 |
Correct |
69 ms |
16140 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
30 ms |
6688 KB |
Output is correct |
21 |
Correct |
135 ms |
26116 KB |
Output is correct |
22 |
Correct |
111 ms |
26108 KB |
Output is correct |
23 |
Correct |
122 ms |
25936 KB |
Output is correct |
24 |
Correct |
122 ms |
26192 KB |
Output is correct |
25 |
Correct |
57 ms |
16120 KB |
Output is correct |
26 |
Correct |
95 ms |
16208 KB |
Output is correct |
27 |
Correct |
143 ms |
26124 KB |
Output is correct |
28 |
Correct |
116 ms |
26124 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
5 ms |
1372 KB |
Output is correct |
37 |
Correct |
150 ms |
28156 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
5 ms |
1456 KB |
Output is correct |
41 |
Correct |
131 ms |
28068 KB |
Output is correct |
42 |
Correct |
0 ms |
344 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
4 ms |
1168 KB |
Output is correct |
45 |
Correct |
65 ms |
18256 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
29 ms |
7236 KB |
Output is correct |
50 |
Correct |
120 ms |
28016 KB |
Output is correct |
51 |
Correct |
141 ms |
27984 KB |
Output is correct |
52 |
Correct |
132 ms |
27892 KB |
Output is correct |
53 |
Correct |
96 ms |
18256 KB |
Output is correct |
54 |
Correct |
56 ms |
18000 KB |
Output is correct |
55 |
Correct |
159 ms |
28132 KB |
Output is correct |
56 |
Correct |
124 ms |
27884 KB |
Output is correct |
57 |
Correct |
69 ms |
18172 KB |
Output is correct |
58 |
Correct |
0 ms |
348 KB |
Output is correct |
59 |
Correct |
0 ms |
344 KB |
Output is correct |
60 |
Correct |
5 ms |
1116 KB |
Output is correct |
61 |
Correct |
66 ms |
18004 KB |
Output is correct |
62 |
Correct |
1 ms |
348 KB |
Output is correct |
63 |
Correct |
1 ms |
348 KB |
Output is correct |
64 |
Correct |
1 ms |
344 KB |
Output is correct |
65 |
Correct |
39 ms |
7228 KB |
Output is correct |
66 |
Correct |
53 ms |
18048 KB |
Output is correct |
67 |
Correct |
53 ms |
18000 KB |
Output is correct |
68 |
Correct |
52 ms |
18004 KB |
Output is correct |
69 |
Correct |
52 ms |
18260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
10 ms |
1464 KB |
Output is correct |
7 |
Correct |
125 ms |
25960 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
1372 KB |
Output is correct |
13 |
Correct |
121 ms |
26012 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
860 KB |
Output is correct |
17 |
Correct |
69 ms |
16140 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
30 ms |
6688 KB |
Output is correct |
21 |
Correct |
135 ms |
26116 KB |
Output is correct |
22 |
Correct |
111 ms |
26108 KB |
Output is correct |
23 |
Correct |
122 ms |
25936 KB |
Output is correct |
24 |
Correct |
122 ms |
26192 KB |
Output is correct |
25 |
Correct |
57 ms |
16120 KB |
Output is correct |
26 |
Correct |
95 ms |
16208 KB |
Output is correct |
27 |
Correct |
143 ms |
26124 KB |
Output is correct |
28 |
Correct |
116 ms |
26124 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
5 ms |
1372 KB |
Output is correct |
37 |
Correct |
150 ms |
28156 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
5 ms |
1456 KB |
Output is correct |
41 |
Correct |
131 ms |
28068 KB |
Output is correct |
42 |
Correct |
0 ms |
344 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
4 ms |
1168 KB |
Output is correct |
45 |
Correct |
65 ms |
18256 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
29 ms |
7236 KB |
Output is correct |
50 |
Correct |
120 ms |
28016 KB |
Output is correct |
51 |
Correct |
141 ms |
27984 KB |
Output is correct |
52 |
Correct |
132 ms |
27892 KB |
Output is correct |
53 |
Correct |
96 ms |
18256 KB |
Output is correct |
54 |
Correct |
56 ms |
18000 KB |
Output is correct |
55 |
Correct |
159 ms |
28132 KB |
Output is correct |
56 |
Correct |
124 ms |
27884 KB |
Output is correct |
57 |
Correct |
69 ms |
18172 KB |
Output is correct |
58 |
Correct |
0 ms |
348 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
1 ms |
348 KB |
Output is correct |
61 |
Correct |
49 ms |
6744 KB |
Output is correct |
62 |
Correct |
126 ms |
25996 KB |
Output is correct |
63 |
Correct |
155 ms |
26196 KB |
Output is correct |
64 |
Correct |
137 ms |
26120 KB |
Output is correct |
65 |
Correct |
1 ms |
348 KB |
Output is correct |
66 |
Correct |
55 ms |
6812 KB |
Output is correct |
67 |
Correct |
134 ms |
26124 KB |
Output is correct |
68 |
Correct |
145 ms |
25936 KB |
Output is correct |
69 |
Correct |
122 ms |
25936 KB |
Output is correct |
70 |
Correct |
0 ms |
344 KB |
Output is correct |
71 |
Correct |
0 ms |
348 KB |
Output is correct |
72 |
Correct |
0 ms |
348 KB |
Output is correct |
73 |
Correct |
26 ms |
6796 KB |
Output is correct |
74 |
Correct |
106 ms |
26020 KB |
Output is correct |
75 |
Correct |
121 ms |
25936 KB |
Output is correct |
76 |
Correct |
110 ms |
25940 KB |
Output is correct |
77 |
Correct |
128 ms |
26192 KB |
Output is correct |
78 |
Correct |
0 ms |
348 KB |
Output is correct |
79 |
Correct |
0 ms |
344 KB |
Output is correct |
80 |
Correct |
5 ms |
1116 KB |
Output is correct |
81 |
Correct |
66 ms |
18004 KB |
Output is correct |
82 |
Correct |
1 ms |
348 KB |
Output is correct |
83 |
Correct |
1 ms |
348 KB |
Output is correct |
84 |
Correct |
1 ms |
344 KB |
Output is correct |
85 |
Correct |
39 ms |
7228 KB |
Output is correct |
86 |
Correct |
53 ms |
18048 KB |
Output is correct |
87 |
Correct |
53 ms |
18000 KB |
Output is correct |
88 |
Correct |
52 ms |
18004 KB |
Output is correct |
89 |
Correct |
52 ms |
18260 KB |
Output is correct |
90 |
Correct |
0 ms |
344 KB |
Output is correct |
91 |
Correct |
0 ms |
348 KB |
Output is correct |
92 |
Correct |
3 ms |
1116 KB |
Output is correct |
93 |
Correct |
65 ms |
18004 KB |
Output is correct |
94 |
Correct |
0 ms |
348 KB |
Output is correct |
95 |
Correct |
0 ms |
348 KB |
Output is correct |
96 |
Correct |
0 ms |
348 KB |
Output is correct |
97 |
Correct |
14 ms |
4856 KB |
Output is correct |
98 |
Correct |
62 ms |
18000 KB |
Output is correct |
99 |
Correct |
53 ms |
18004 KB |
Output is correct |
100 |
Correct |
52 ms |
18000 KB |
Output is correct |
101 |
Correct |
62 ms |
18260 KB |
Output is correct |
102 |
Correct |
75 ms |
18296 KB |
Output is correct |
103 |
Correct |
55 ms |
18176 KB |
Output is correct |
104 |
Correct |
61 ms |
18048 KB |
Output is correct |
105 |
Correct |
69 ms |
18256 KB |
Output is correct |