#include "bits/stdc++.h"
#include "supertrees.h"
using namespace std;
#define ll long long
#define sz(a) (int)a.size()
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define forn(i, n) for(int i=0;i < n; ++i)
const int N = 1005;
int par[N], ways[N][N];
bool vis[N];
bool ok = true;
int get(int a) {
return par[a] = (par[a] == a ? a : get(par[a]));
}
void uni(int a, int b) {
a = get(a);
b = get(b);
par[a] = b;
}
vector<int> adj[N];
void dfs(int u, int start) {
vis[u] = true;
if(++ways[start][u] >= 3 || !ok) {
ok = false;
return;
}
for(int v: adj[u]) {
if(!vis[v]) {
dfs(v, start);
}
}
vis[u] = false;
}
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
forn(i, n) forn(j, n) if(p[i][j] == 3) return 0;
forn(i, n) par[i] = i;
std::vector<std::vector<int>> answer(n, vector<int>(n, 0));
for(int i = 0; i < n; ++i) {
for(int j = i + 1; j < n; ++j) {
if(p[i][j] == 1 && get(i) != get(j)) {
answer[i][j] = answer[j][i] = 1;
uni(i, j);
}
}
}
for(int i = 0; i < n; ++i) {
vector<int> v;
v.pb(i);
for(int j = i + 1; j < n; ++j) {
if(get(i) != get(j) && p[get(i)][get(j)] == 2) {
v.pb(j);
uni(i, j);
}
}
if(sz(v) >= 2) {
for(int k = 0; k < sz(v); ++k) {
answer[v[k]][v[(k + 1) % sz(v)]] = answer[v[(k + 1) % sz(v)]][v[k]] = 1;
}
}
}
for(int i = 0; i < n; ++i) {
for(int j = i + 1; j < n; ++j) {
if(answer[i][j]) {
adj[i].pb(j);
adj[j].pb(i);
}
}
}
forn(i, n) {
forn(j, n) {
if(get(i) == get(j) && !p[i][j]) return 0;
if(get(i) != get(j) && p[i][j]) return 0;
}
}
forn(i, n) dfs(i, i);
if(!ok) return 0;
for(int i = 0; i < n; ++i) {
for(int j = i + 1; j < n; ++j) {
if(ways[i][j] != p[i][j]) return 0;
}
}
build(answer);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
8 ms |
2008 KB |
Output is correct |
7 |
Correct |
190 ms |
26172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
8 ms |
2008 KB |
Output is correct |
7 |
Correct |
190 ms |
26172 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
8 ms |
1948 KB |
Output is correct |
13 |
Correct |
190 ms |
26100 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
6 ms |
852 KB |
Output is correct |
17 |
Correct |
89 ms |
12344 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
51 ms |
7940 KB |
Output is correct |
21 |
Correct |
193 ms |
26188 KB |
Output is correct |
22 |
Correct |
188 ms |
26188 KB |
Output is correct |
23 |
Correct |
204 ms |
26156 KB |
Output is correct |
24 |
Correct |
178 ms |
26072 KB |
Output is correct |
25 |
Correct |
78 ms |
12352 KB |
Output is correct |
26 |
Correct |
76 ms |
12304 KB |
Output is correct |
27 |
Correct |
209 ms |
26300 KB |
Output is correct |
28 |
Correct |
173 ms |
26140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
8 ms |
2004 KB |
Output is correct |
9 |
Correct |
175 ms |
26120 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
9 ms |
2004 KB |
Output is correct |
13 |
Correct |
204 ms |
26140 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
4 ms |
852 KB |
Output is correct |
17 |
Correct |
83 ms |
12332 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
48 ms |
7864 KB |
Output is correct |
22 |
Correct |
190 ms |
26184 KB |
Output is correct |
23 |
Correct |
196 ms |
26148 KB |
Output is correct |
24 |
Correct |
204 ms |
26188 KB |
Output is correct |
25 |
Correct |
78 ms |
16180 KB |
Output is correct |
26 |
Correct |
78 ms |
12320 KB |
Output is correct |
27 |
Correct |
190 ms |
26188 KB |
Output is correct |
28 |
Correct |
212 ms |
26172 KB |
Output is correct |
29 |
Correct |
81 ms |
16204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
51 ms |
7872 KB |
Output is correct |
5 |
Correct |
192 ms |
26252 KB |
Output is correct |
6 |
Correct |
187 ms |
26168 KB |
Output is correct |
7 |
Correct |
206 ms |
26344 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
52 ms |
7864 KB |
Output is correct |
10 |
Correct |
195 ms |
26152 KB |
Output is correct |
11 |
Correct |
182 ms |
26172 KB |
Output is correct |
12 |
Correct |
202 ms |
26128 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
47 ms |
7820 KB |
Output is correct |
17 |
Correct |
187 ms |
26176 KB |
Output is correct |
18 |
Correct |
194 ms |
26224 KB |
Output is correct |
19 |
Correct |
195 ms |
26136 KB |
Output is correct |
20 |
Correct |
179 ms |
26188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
8 ms |
2008 KB |
Output is correct |
7 |
Correct |
190 ms |
26172 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
8 ms |
1948 KB |
Output is correct |
13 |
Correct |
190 ms |
26100 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
6 ms |
852 KB |
Output is correct |
17 |
Correct |
89 ms |
12344 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
51 ms |
7940 KB |
Output is correct |
21 |
Correct |
193 ms |
26188 KB |
Output is correct |
22 |
Correct |
188 ms |
26188 KB |
Output is correct |
23 |
Correct |
204 ms |
26156 KB |
Output is correct |
24 |
Correct |
178 ms |
26072 KB |
Output is correct |
25 |
Correct |
78 ms |
12352 KB |
Output is correct |
26 |
Correct |
76 ms |
12304 KB |
Output is correct |
27 |
Correct |
209 ms |
26300 KB |
Output is correct |
28 |
Correct |
173 ms |
26140 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
0 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
8 ms |
2004 KB |
Output is correct |
37 |
Correct |
175 ms |
26120 KB |
Output is correct |
38 |
Correct |
1 ms |
336 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
9 ms |
2004 KB |
Output is correct |
41 |
Correct |
204 ms |
26140 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
4 ms |
852 KB |
Output is correct |
45 |
Correct |
83 ms |
12332 KB |
Output is correct |
46 |
Correct |
1 ms |
336 KB |
Output is correct |
47 |
Correct |
0 ms |
340 KB |
Output is correct |
48 |
Correct |
1 ms |
332 KB |
Output is correct |
49 |
Correct |
48 ms |
7864 KB |
Output is correct |
50 |
Correct |
190 ms |
26184 KB |
Output is correct |
51 |
Correct |
196 ms |
26148 KB |
Output is correct |
52 |
Correct |
204 ms |
26188 KB |
Output is correct |
53 |
Correct |
78 ms |
16180 KB |
Output is correct |
54 |
Correct |
78 ms |
12320 KB |
Output is correct |
55 |
Correct |
190 ms |
26188 KB |
Output is correct |
56 |
Correct |
212 ms |
26172 KB |
Output is correct |
57 |
Correct |
81 ms |
16204 KB |
Output is correct |
58 |
Correct |
1 ms |
340 KB |
Output is correct |
59 |
Correct |
0 ms |
340 KB |
Output is correct |
60 |
Correct |
4 ms |
852 KB |
Output is correct |
61 |
Correct |
80 ms |
12356 KB |
Output is correct |
62 |
Correct |
1 ms |
340 KB |
Output is correct |
63 |
Correct |
1 ms |
340 KB |
Output is correct |
64 |
Correct |
1 ms |
340 KB |
Output is correct |
65 |
Correct |
48 ms |
7828 KB |
Output is correct |
66 |
Correct |
80 ms |
12352 KB |
Output is correct |
67 |
Correct |
76 ms |
12348 KB |
Output is correct |
68 |
Correct |
76 ms |
12396 KB |
Output is correct |
69 |
Correct |
79 ms |
16236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
8 ms |
2008 KB |
Output is correct |
7 |
Correct |
190 ms |
26172 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
8 ms |
1948 KB |
Output is correct |
13 |
Correct |
190 ms |
26100 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
6 ms |
852 KB |
Output is correct |
17 |
Correct |
89 ms |
12344 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
51 ms |
7940 KB |
Output is correct |
21 |
Correct |
193 ms |
26188 KB |
Output is correct |
22 |
Correct |
188 ms |
26188 KB |
Output is correct |
23 |
Correct |
204 ms |
26156 KB |
Output is correct |
24 |
Correct |
178 ms |
26072 KB |
Output is correct |
25 |
Correct |
78 ms |
12352 KB |
Output is correct |
26 |
Correct |
76 ms |
12304 KB |
Output is correct |
27 |
Correct |
209 ms |
26300 KB |
Output is correct |
28 |
Correct |
173 ms |
26140 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
0 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
8 ms |
2004 KB |
Output is correct |
37 |
Correct |
175 ms |
26120 KB |
Output is correct |
38 |
Correct |
1 ms |
336 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
9 ms |
2004 KB |
Output is correct |
41 |
Correct |
204 ms |
26140 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
4 ms |
852 KB |
Output is correct |
45 |
Correct |
83 ms |
12332 KB |
Output is correct |
46 |
Correct |
1 ms |
336 KB |
Output is correct |
47 |
Correct |
0 ms |
340 KB |
Output is correct |
48 |
Correct |
1 ms |
332 KB |
Output is correct |
49 |
Correct |
48 ms |
7864 KB |
Output is correct |
50 |
Correct |
190 ms |
26184 KB |
Output is correct |
51 |
Correct |
196 ms |
26148 KB |
Output is correct |
52 |
Correct |
204 ms |
26188 KB |
Output is correct |
53 |
Correct |
78 ms |
16180 KB |
Output is correct |
54 |
Correct |
78 ms |
12320 KB |
Output is correct |
55 |
Correct |
190 ms |
26188 KB |
Output is correct |
56 |
Correct |
212 ms |
26172 KB |
Output is correct |
57 |
Correct |
81 ms |
16204 KB |
Output is correct |
58 |
Correct |
0 ms |
340 KB |
Output is correct |
59 |
Correct |
0 ms |
340 KB |
Output is correct |
60 |
Correct |
0 ms |
332 KB |
Output is correct |
61 |
Correct |
51 ms |
7872 KB |
Output is correct |
62 |
Correct |
192 ms |
26252 KB |
Output is correct |
63 |
Correct |
187 ms |
26168 KB |
Output is correct |
64 |
Correct |
206 ms |
26344 KB |
Output is correct |
65 |
Correct |
0 ms |
340 KB |
Output is correct |
66 |
Correct |
52 ms |
7864 KB |
Output is correct |
67 |
Correct |
195 ms |
26152 KB |
Output is correct |
68 |
Correct |
182 ms |
26172 KB |
Output is correct |
69 |
Correct |
202 ms |
26128 KB |
Output is correct |
70 |
Correct |
1 ms |
340 KB |
Output is correct |
71 |
Correct |
0 ms |
340 KB |
Output is correct |
72 |
Correct |
1 ms |
340 KB |
Output is correct |
73 |
Correct |
47 ms |
7820 KB |
Output is correct |
74 |
Correct |
187 ms |
26176 KB |
Output is correct |
75 |
Correct |
194 ms |
26224 KB |
Output is correct |
76 |
Correct |
195 ms |
26136 KB |
Output is correct |
77 |
Correct |
179 ms |
26188 KB |
Output is correct |
78 |
Correct |
1 ms |
340 KB |
Output is correct |
79 |
Correct |
0 ms |
340 KB |
Output is correct |
80 |
Correct |
4 ms |
852 KB |
Output is correct |
81 |
Correct |
80 ms |
12356 KB |
Output is correct |
82 |
Correct |
1 ms |
340 KB |
Output is correct |
83 |
Correct |
1 ms |
340 KB |
Output is correct |
84 |
Correct |
1 ms |
340 KB |
Output is correct |
85 |
Correct |
48 ms |
7828 KB |
Output is correct |
86 |
Correct |
80 ms |
12352 KB |
Output is correct |
87 |
Correct |
76 ms |
12348 KB |
Output is correct |
88 |
Correct |
76 ms |
12396 KB |
Output is correct |
89 |
Correct |
79 ms |
16236 KB |
Output is correct |
90 |
Correct |
1 ms |
340 KB |
Output is correct |
91 |
Correct |
1 ms |
212 KB |
Output is correct |
92 |
Correct |
3 ms |
596 KB |
Output is correct |
93 |
Correct |
68 ms |
8388 KB |
Output is correct |
94 |
Correct |
0 ms |
212 KB |
Output is correct |
95 |
Correct |
1 ms |
212 KB |
Output is correct |
96 |
Correct |
1 ms |
340 KB |
Output is correct |
97 |
Correct |
16 ms |
2720 KB |
Output is correct |
98 |
Correct |
62 ms |
10132 KB |
Output is correct |
99 |
Correct |
64 ms |
10060 KB |
Output is correct |
100 |
Correct |
61 ms |
10148 KB |
Output is correct |
101 |
Correct |
64 ms |
10136 KB |
Output is correct |
102 |
Correct |
63 ms |
10136 KB |
Output is correct |
103 |
Correct |
62 ms |
10060 KB |
Output is correct |
104 |
Correct |
62 ms |
10136 KB |
Output is correct |
105 |
Correct |
70 ms |
10148 KB |
Output is correct |