#include "supertrees.h"
#include <bits/stdc++.h>
#define iter(a) a.begin(), a.end()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(iter(a), greater<>())
#define eb emplace_back
#define ef emplace_front
#define pob pop_back()
#define pof pop_front()
#define mp make_pair
#define F first
#define S second
#define uni(a) a.resize(unique(iter(a)) - a.begin())
#define printv(a, b) { \
for(auto pv : a) b << pv << " "; \
b << "\n"; \
}
using namespace std;
typedef long long ll;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
return o << '(' << p.F << ',' << p.S << ')';
}
int n;
vector<vector<int>> g;
vector<int> vst1, vst2;
vector<vector<int>> cy;
vector<vector<int>> ans;
void dfs1(int now, int id){
vst1[now] = id;
for(int i = 0; i < n; i++){
if(g[now][i] != 1) continue;
if(vst1[i] != -1) continue;
ans[now][i] = ans[i][now] = 1;
dfs1(i, id);
}
}
void dfs2(int now, int id){
vst2[now] = id;
cy[id].eb(vst1[now]);
for(int i = 0; i < n; i++){
if(g[now][i] != 1 && g[now][i] != 2) continue;
if(vst2[i] != -1) continue;
dfs2(i, id);
}
}
int construct(vector<vector<int>> p){
n = p.size();
g = p;
vst1.resize(n, -1);
vst2.resize(n, -1);
cy.resize(n);
ans.resize(n, vector<int>(n));
for(int i = 0; i < n; i++){
if(vst1[i] != -1) continue;
dfs1(i, i);
}
for(int i = 0; i < n; i++){
if(vst2[i] != -1) continue;
dfs2(i, i);
lsort(cy[i]);
uni(cy[i]);
if(cy[i].size() == 1) continue;
if(cy[i].size() == 2) return 0;
int lst = cy[i].back();
for(int j : cy[i]){
ans[lst][j] = ans[j][lst] = 1;
lst = j;
}
}
//printv(vst1, cerr);
//printv(vst2, cerr);
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
int t;
if(vst1[i] == vst1[j]) t = 1;
else if(vst2[i] == vst2[j]) t = 2;
else t = 0;
//cerr << "exp " << i << " " << j << " " << t << "\n";
if(g[i][j] != t) return 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 |
1 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 |
7 ms |
1324 KB |
Output is correct |
7 |
Correct |
210 ms |
25988 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 |
1 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 |
7 ms |
1324 KB |
Output is correct |
7 |
Correct |
210 ms |
25988 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
304 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
296 KB |
Output is correct |
12 |
Correct |
8 ms |
1400 KB |
Output is correct |
13 |
Correct |
187 ms |
27928 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
920 KB |
Output is correct |
17 |
Correct |
92 ms |
18044 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
54 ms |
7236 KB |
Output is correct |
21 |
Correct |
212 ms |
27960 KB |
Output is correct |
22 |
Correct |
234 ms |
27892 KB |
Output is correct |
23 |
Correct |
217 ms |
27972 KB |
Output is correct |
24 |
Correct |
183 ms |
27904 KB |
Output is correct |
25 |
Correct |
82 ms |
18032 KB |
Output is correct |
26 |
Correct |
86 ms |
18088 KB |
Output is correct |
27 |
Correct |
192 ms |
27928 KB |
Output is correct |
28 |
Correct |
184 ms |
27964 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 |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
8 ms |
1364 KB |
Output is correct |
9 |
Correct |
171 ms |
26004 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
300 KB |
Output is correct |
12 |
Correct |
10 ms |
1380 KB |
Output is correct |
13 |
Correct |
190 ms |
28016 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
292 KB |
Output is correct |
16 |
Correct |
5 ms |
952 KB |
Output is correct |
17 |
Correct |
125 ms |
18032 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 |
212 KB |
Output is correct |
21 |
Correct |
43 ms |
7152 KB |
Output is correct |
22 |
Correct |
205 ms |
27980 KB |
Output is correct |
23 |
Correct |
204 ms |
27988 KB |
Output is correct |
24 |
Correct |
215 ms |
28024 KB |
Output is correct |
25 |
Correct |
88 ms |
18032 KB |
Output is correct |
26 |
Correct |
81 ms |
18036 KB |
Output is correct |
27 |
Correct |
204 ms |
28028 KB |
Output is correct |
28 |
Correct |
184 ms |
27904 KB |
Output is correct |
29 |
Correct |
81 ms |
17996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
54 ms |
6768 KB |
Output is correct |
5 |
Correct |
188 ms |
27908 KB |
Output is correct |
6 |
Correct |
207 ms |
28008 KB |
Output is correct |
7 |
Correct |
198 ms |
28020 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
57 ms |
7196 KB |
Output is correct |
10 |
Correct |
182 ms |
27904 KB |
Output is correct |
11 |
Correct |
219 ms |
27980 KB |
Output is correct |
12 |
Correct |
178 ms |
27988 KB |
Output is correct |
13 |
Correct |
1 ms |
304 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
54 ms |
7232 KB |
Output is correct |
17 |
Correct |
197 ms |
27968 KB |
Output is correct |
18 |
Correct |
200 ms |
27896 KB |
Output is correct |
19 |
Correct |
193 ms |
27980 KB |
Output is correct |
20 |
Correct |
198 ms |
28012 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 |
1 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 |
7 ms |
1324 KB |
Output is correct |
7 |
Correct |
210 ms |
25988 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
304 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
296 KB |
Output is correct |
12 |
Correct |
8 ms |
1400 KB |
Output is correct |
13 |
Correct |
187 ms |
27928 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
920 KB |
Output is correct |
17 |
Correct |
92 ms |
18044 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
54 ms |
7236 KB |
Output is correct |
21 |
Correct |
212 ms |
27960 KB |
Output is correct |
22 |
Correct |
234 ms |
27892 KB |
Output is correct |
23 |
Correct |
217 ms |
27972 KB |
Output is correct |
24 |
Correct |
183 ms |
27904 KB |
Output is correct |
25 |
Correct |
82 ms |
18032 KB |
Output is correct |
26 |
Correct |
86 ms |
18088 KB |
Output is correct |
27 |
Correct |
192 ms |
27928 KB |
Output is correct |
28 |
Correct |
184 ms |
27964 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
8 ms |
1364 KB |
Output is correct |
37 |
Correct |
171 ms |
26004 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
300 KB |
Output is correct |
40 |
Correct |
10 ms |
1380 KB |
Output is correct |
41 |
Correct |
190 ms |
28016 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
292 KB |
Output is correct |
44 |
Correct |
5 ms |
952 KB |
Output is correct |
45 |
Correct |
125 ms |
18032 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 |
212 KB |
Output is correct |
49 |
Correct |
43 ms |
7152 KB |
Output is correct |
50 |
Correct |
205 ms |
27980 KB |
Output is correct |
51 |
Correct |
204 ms |
27988 KB |
Output is correct |
52 |
Correct |
215 ms |
28024 KB |
Output is correct |
53 |
Correct |
88 ms |
18032 KB |
Output is correct |
54 |
Correct |
81 ms |
18036 KB |
Output is correct |
55 |
Correct |
204 ms |
28028 KB |
Output is correct |
56 |
Correct |
184 ms |
27904 KB |
Output is correct |
57 |
Correct |
81 ms |
17996 KB |
Output is correct |
58 |
Correct |
1 ms |
304 KB |
Output is correct |
59 |
Correct |
1 ms |
212 KB |
Output is correct |
60 |
Correct |
4 ms |
980 KB |
Output is correct |
61 |
Correct |
95 ms |
18124 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 |
45 ms |
7160 KB |
Output is correct |
66 |
Correct |
82 ms |
18088 KB |
Output is correct |
67 |
Correct |
79 ms |
18040 KB |
Output is correct |
68 |
Correct |
79 ms |
18200 KB |
Output is correct |
69 |
Correct |
106 ms |
18032 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 |
1 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 |
7 ms |
1324 KB |
Output is correct |
7 |
Correct |
210 ms |
25988 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
304 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
296 KB |
Output is correct |
12 |
Correct |
8 ms |
1400 KB |
Output is correct |
13 |
Correct |
187 ms |
27928 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
920 KB |
Output is correct |
17 |
Correct |
92 ms |
18044 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
54 ms |
7236 KB |
Output is correct |
21 |
Correct |
212 ms |
27960 KB |
Output is correct |
22 |
Correct |
234 ms |
27892 KB |
Output is correct |
23 |
Correct |
217 ms |
27972 KB |
Output is correct |
24 |
Correct |
183 ms |
27904 KB |
Output is correct |
25 |
Correct |
82 ms |
18032 KB |
Output is correct |
26 |
Correct |
86 ms |
18088 KB |
Output is correct |
27 |
Correct |
192 ms |
27928 KB |
Output is correct |
28 |
Correct |
184 ms |
27964 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
8 ms |
1364 KB |
Output is correct |
37 |
Correct |
171 ms |
26004 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
300 KB |
Output is correct |
40 |
Correct |
10 ms |
1380 KB |
Output is correct |
41 |
Correct |
190 ms |
28016 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
292 KB |
Output is correct |
44 |
Correct |
5 ms |
952 KB |
Output is correct |
45 |
Correct |
125 ms |
18032 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 |
212 KB |
Output is correct |
49 |
Correct |
43 ms |
7152 KB |
Output is correct |
50 |
Correct |
205 ms |
27980 KB |
Output is correct |
51 |
Correct |
204 ms |
27988 KB |
Output is correct |
52 |
Correct |
215 ms |
28024 KB |
Output is correct |
53 |
Correct |
88 ms |
18032 KB |
Output is correct |
54 |
Correct |
81 ms |
18036 KB |
Output is correct |
55 |
Correct |
204 ms |
28028 KB |
Output is correct |
56 |
Correct |
184 ms |
27904 KB |
Output is correct |
57 |
Correct |
81 ms |
17996 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
212 KB |
Output is correct |
60 |
Correct |
1 ms |
212 KB |
Output is correct |
61 |
Correct |
54 ms |
6768 KB |
Output is correct |
62 |
Correct |
188 ms |
27908 KB |
Output is correct |
63 |
Correct |
207 ms |
28008 KB |
Output is correct |
64 |
Correct |
198 ms |
28020 KB |
Output is correct |
65 |
Correct |
1 ms |
212 KB |
Output is correct |
66 |
Correct |
57 ms |
7196 KB |
Output is correct |
67 |
Correct |
182 ms |
27904 KB |
Output is correct |
68 |
Correct |
219 ms |
27980 KB |
Output is correct |
69 |
Correct |
178 ms |
27988 KB |
Output is correct |
70 |
Correct |
1 ms |
304 KB |
Output is correct |
71 |
Correct |
1 ms |
212 KB |
Output is correct |
72 |
Correct |
1 ms |
212 KB |
Output is correct |
73 |
Correct |
54 ms |
7232 KB |
Output is correct |
74 |
Correct |
197 ms |
27968 KB |
Output is correct |
75 |
Correct |
200 ms |
27896 KB |
Output is correct |
76 |
Correct |
193 ms |
27980 KB |
Output is correct |
77 |
Correct |
198 ms |
28012 KB |
Output is correct |
78 |
Correct |
1 ms |
304 KB |
Output is correct |
79 |
Correct |
1 ms |
212 KB |
Output is correct |
80 |
Correct |
4 ms |
980 KB |
Output is correct |
81 |
Correct |
95 ms |
18124 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 |
45 ms |
7160 KB |
Output is correct |
86 |
Correct |
82 ms |
18088 KB |
Output is correct |
87 |
Correct |
79 ms |
18040 KB |
Output is correct |
88 |
Correct |
79 ms |
18200 KB |
Output is correct |
89 |
Correct |
106 ms |
18032 KB |
Output is correct |
90 |
Correct |
1 ms |
212 KB |
Output is correct |
91 |
Correct |
1 ms |
296 KB |
Output is correct |
92 |
Correct |
6 ms |
980 KB |
Output is correct |
93 |
Correct |
111 ms |
18044 KB |
Output is correct |
94 |
Correct |
1 ms |
212 KB |
Output is correct |
95 |
Correct |
1 ms |
304 KB |
Output is correct |
96 |
Correct |
1 ms |
304 KB |
Output is correct |
97 |
Correct |
25 ms |
4728 KB |
Output is correct |
98 |
Correct |
98 ms |
18076 KB |
Output is correct |
99 |
Correct |
83 ms |
18044 KB |
Output is correct |
100 |
Correct |
88 ms |
18036 KB |
Output is correct |
101 |
Correct |
108 ms |
18036 KB |
Output is correct |
102 |
Correct |
96 ms |
18032 KB |
Output is correct |
103 |
Correct |
93 ms |
18036 KB |
Output is correct |
104 |
Correct |
114 ms |
18192 KB |
Output is correct |
105 |
Correct |
124 ms |
18032 KB |
Output is correct |