#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
#define fi first
#define se second
#define _size(x) (int)x.size()
#define BIT(i, x) ((x >> i) & 1)
#define MASK(n) ((1 << n) - 1)
#define REP(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define FOR(i, a, b) for (int i = a, _b = (b); i <= _b; i++)
#define FORD(i, a, b) for (int i = a, _b = (b); i >= _b; i--)
#define FORB1(i, mask) for (int i = mask; i > 0; i ^= i & - i)
#define FORB0(i, n, mask) for (int i = ((1 << n) - 1) ^ mask; i > 0; i ^= i & - i)
#define FORALL(i, a) for (auto i: a)
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
vector<int> root;
int getroot(int u) {
return root[u] == u ? u : (root[u] = getroot(root[u]));
}
bool unite(int u, int v) {
u = getroot(u), v = getroot(v);
if (u == v) return false;
root[v] = u;
return true;
}
int construct(vector<vector<int>> p) {
int n = _size(p);
root.resize(n);
REP(i, n) root[i] = i;
REP(i, n) REP(j, n) {
if (i == j) {
if (p[i][j] != 1) return 0;
continue;
}
if (p[i][j] == 1) unite(i, j);
if (p[i][j] > 2) return 0;
}
vector<vector<int>> adj(n);
REP(i, n) adj[getroot(i)].push_back(i);
vector<int> used(n);
vector<pair<int, int>> ans;
vector<vector<int>> cnt(n, vector<int>(n));
REP(i, n) {
if (!_size(adj[i]) || used[i]) continue;
FORALL(u, adj[i]) used[u]++;
FORALL(u, adj[i]) FORALL(v, adj[i]) cnt[u][v] = 1;
REP(j, _size(adj[i]) - 1) ans.push_back({adj[i][j], adj[i][j + 1]});
vector<int> g;
g.push_back(i);
REP(j, n) if (p[i][j] == 2) {
used[j]++;
g.push_back(j);
}
if (_size(g) == 1) continue;
if (_size(g) == 2) return 0;
FORALL(u, g) FORALL(v, g) if (u != v) cnt[u][v] = 2; else cnt[u][v] = 1;
FORALL(u, g) FORALL(v, adj[i]) {
if (u == i || v == i) continue;
cnt[u][v] = cnt[v][u] = 2;
}
REP(j, _size(g) - 1) ans.push_back({g[j], g[j + 1]});
ans.push_back({g[0], g.back()});
}
REP(i, n) cnt[i][i] = 1;
REP(i, n) REP(j, n) if (cnt[i][j] != p[i][j]) return 0;
vector<vector<int>> b(n, vector<int>(n));
FORALL(e, ans) b[e.fi][e.se] = b[e.se][e.fi] = 1;
build(b);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
7 ms |
1568 KB |
Output is correct |
7 |
Correct |
151 ms |
28072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
7 ms |
1568 KB |
Output is correct |
7 |
Correct |
151 ms |
28072 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
6 ms |
1368 KB |
Output is correct |
13 |
Correct |
148 ms |
27984 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
3 ms |
856 KB |
Output is correct |
17 |
Correct |
69 ms |
14160 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
41 ms |
7268 KB |
Output is correct |
21 |
Correct |
148 ms |
28276 KB |
Output is correct |
22 |
Correct |
152 ms |
28172 KB |
Output is correct |
23 |
Correct |
154 ms |
28112 KB |
Output is correct |
24 |
Correct |
176 ms |
28024 KB |
Output is correct |
25 |
Correct |
60 ms |
14160 KB |
Output is correct |
26 |
Correct |
58 ms |
14172 KB |
Output is correct |
27 |
Correct |
153 ms |
27984 KB |
Output is correct |
28 |
Correct |
149 ms |
27996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
6 ms |
1368 KB |
Output is correct |
9 |
Correct |
145 ms |
28240 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
6 ms |
1368 KB |
Output is correct |
13 |
Correct |
149 ms |
27984 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
3 ms |
856 KB |
Output is correct |
17 |
Correct |
65 ms |
14164 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
37 ms |
7252 KB |
Output is correct |
22 |
Correct |
146 ms |
27984 KB |
Output is correct |
23 |
Correct |
145 ms |
28168 KB |
Output is correct |
24 |
Correct |
156 ms |
28240 KB |
Output is correct |
25 |
Correct |
58 ms |
14164 KB |
Output is correct |
26 |
Correct |
59 ms |
14160 KB |
Output is correct |
27 |
Correct |
151 ms |
28024 KB |
Output is correct |
28 |
Correct |
151 ms |
28040 KB |
Output is correct |
29 |
Correct |
59 ms |
14160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
39 ms |
7272 KB |
Output is correct |
5 |
Correct |
149 ms |
27984 KB |
Output is correct |
6 |
Correct |
161 ms |
28096 KB |
Output is correct |
7 |
Correct |
154 ms |
27984 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
37 ms |
7420 KB |
Output is correct |
10 |
Correct |
145 ms |
27984 KB |
Output is correct |
11 |
Correct |
146 ms |
27984 KB |
Output is correct |
12 |
Correct |
154 ms |
28156 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Incorrect |
15 ms |
3772 KB |
Answer gives possible 0 while actual possible 1 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
7 ms |
1568 KB |
Output is correct |
7 |
Correct |
151 ms |
28072 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
6 ms |
1368 KB |
Output is correct |
13 |
Correct |
148 ms |
27984 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
3 ms |
856 KB |
Output is correct |
17 |
Correct |
69 ms |
14160 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
41 ms |
7268 KB |
Output is correct |
21 |
Correct |
148 ms |
28276 KB |
Output is correct |
22 |
Correct |
152 ms |
28172 KB |
Output is correct |
23 |
Correct |
154 ms |
28112 KB |
Output is correct |
24 |
Correct |
176 ms |
28024 KB |
Output is correct |
25 |
Correct |
60 ms |
14160 KB |
Output is correct |
26 |
Correct |
58 ms |
14172 KB |
Output is correct |
27 |
Correct |
153 ms |
27984 KB |
Output is correct |
28 |
Correct |
149 ms |
27996 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
344 KB |
Output is correct |
36 |
Correct |
6 ms |
1368 KB |
Output is correct |
37 |
Correct |
145 ms |
28240 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
344 KB |
Output is correct |
40 |
Correct |
6 ms |
1368 KB |
Output is correct |
41 |
Correct |
149 ms |
27984 KB |
Output is correct |
42 |
Correct |
0 ms |
344 KB |
Output is correct |
43 |
Correct |
0 ms |
344 KB |
Output is correct |
44 |
Correct |
3 ms |
856 KB |
Output is correct |
45 |
Correct |
65 ms |
14164 KB |
Output is correct |
46 |
Correct |
0 ms |
344 KB |
Output is correct |
47 |
Correct |
0 ms |
344 KB |
Output is correct |
48 |
Correct |
0 ms |
344 KB |
Output is correct |
49 |
Correct |
37 ms |
7252 KB |
Output is correct |
50 |
Correct |
146 ms |
27984 KB |
Output is correct |
51 |
Correct |
145 ms |
28168 KB |
Output is correct |
52 |
Correct |
156 ms |
28240 KB |
Output is correct |
53 |
Correct |
58 ms |
14164 KB |
Output is correct |
54 |
Correct |
59 ms |
14160 KB |
Output is correct |
55 |
Correct |
151 ms |
28024 KB |
Output is correct |
56 |
Correct |
151 ms |
28040 KB |
Output is correct |
57 |
Correct |
59 ms |
14160 KB |
Output is correct |
58 |
Correct |
1 ms |
344 KB |
Output is correct |
59 |
Correct |
0 ms |
344 KB |
Output is correct |
60 |
Correct |
3 ms |
856 KB |
Output is correct |
61 |
Correct |
67 ms |
14160 KB |
Output is correct |
62 |
Correct |
0 ms |
344 KB |
Output is correct |
63 |
Correct |
1 ms |
344 KB |
Output is correct |
64 |
Correct |
0 ms |
344 KB |
Output is correct |
65 |
Incorrect |
17 ms |
3932 KB |
Answer gives possible 0 while actual possible 1 |
66 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
7 ms |
1568 KB |
Output is correct |
7 |
Correct |
151 ms |
28072 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
6 ms |
1368 KB |
Output is correct |
13 |
Correct |
148 ms |
27984 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
3 ms |
856 KB |
Output is correct |
17 |
Correct |
69 ms |
14160 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
41 ms |
7268 KB |
Output is correct |
21 |
Correct |
148 ms |
28276 KB |
Output is correct |
22 |
Correct |
152 ms |
28172 KB |
Output is correct |
23 |
Correct |
154 ms |
28112 KB |
Output is correct |
24 |
Correct |
176 ms |
28024 KB |
Output is correct |
25 |
Correct |
60 ms |
14160 KB |
Output is correct |
26 |
Correct |
58 ms |
14172 KB |
Output is correct |
27 |
Correct |
153 ms |
27984 KB |
Output is correct |
28 |
Correct |
149 ms |
27996 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
344 KB |
Output is correct |
36 |
Correct |
6 ms |
1368 KB |
Output is correct |
37 |
Correct |
145 ms |
28240 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
344 KB |
Output is correct |
40 |
Correct |
6 ms |
1368 KB |
Output is correct |
41 |
Correct |
149 ms |
27984 KB |
Output is correct |
42 |
Correct |
0 ms |
344 KB |
Output is correct |
43 |
Correct |
0 ms |
344 KB |
Output is correct |
44 |
Correct |
3 ms |
856 KB |
Output is correct |
45 |
Correct |
65 ms |
14164 KB |
Output is correct |
46 |
Correct |
0 ms |
344 KB |
Output is correct |
47 |
Correct |
0 ms |
344 KB |
Output is correct |
48 |
Correct |
0 ms |
344 KB |
Output is correct |
49 |
Correct |
37 ms |
7252 KB |
Output is correct |
50 |
Correct |
146 ms |
27984 KB |
Output is correct |
51 |
Correct |
145 ms |
28168 KB |
Output is correct |
52 |
Correct |
156 ms |
28240 KB |
Output is correct |
53 |
Correct |
58 ms |
14164 KB |
Output is correct |
54 |
Correct |
59 ms |
14160 KB |
Output is correct |
55 |
Correct |
151 ms |
28024 KB |
Output is correct |
56 |
Correct |
151 ms |
28040 KB |
Output is correct |
57 |
Correct |
59 ms |
14160 KB |
Output is correct |
58 |
Correct |
1 ms |
344 KB |
Output is correct |
59 |
Correct |
1 ms |
344 KB |
Output is correct |
60 |
Correct |
0 ms |
344 KB |
Output is correct |
61 |
Correct |
39 ms |
7272 KB |
Output is correct |
62 |
Correct |
149 ms |
27984 KB |
Output is correct |
63 |
Correct |
161 ms |
28096 KB |
Output is correct |
64 |
Correct |
154 ms |
27984 KB |
Output is correct |
65 |
Correct |
0 ms |
344 KB |
Output is correct |
66 |
Correct |
37 ms |
7420 KB |
Output is correct |
67 |
Correct |
145 ms |
27984 KB |
Output is correct |
68 |
Correct |
146 ms |
27984 KB |
Output is correct |
69 |
Correct |
154 ms |
28156 KB |
Output is correct |
70 |
Correct |
0 ms |
344 KB |
Output is correct |
71 |
Correct |
1 ms |
344 KB |
Output is correct |
72 |
Correct |
0 ms |
344 KB |
Output is correct |
73 |
Incorrect |
15 ms |
3772 KB |
Answer gives possible 0 while actual possible 1 |
74 |
Halted |
0 ms |
0 KB |
- |