#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 && p[i][j] != 1) return 0;
if (p[i][j] > 2) return 0;
if (p[i][j] == 2) unite(i, j);
}
vector<vector<int>> adj(n);
REP(i, n) adj[getroot(i)].push_back(i);
vector<pair<int, int>> ans;
REP(i, n) REP(j, _size(adj[i]) - 1) ans.push_back({adj[i][j], adj[i][j + 1]});
REP(i, n) REP(j, n) {
if (p[i][j] != 1 || i == j) continue;
if (unite(i, j)) ans.push_back({i, j});
}
REP(i, n) REP(j, n) {
if (p[i][j] != 0) continue;
if (getroot(i) == getroot(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 |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
1116 KB |
Output is correct |
7 |
Correct |
163 ms |
22040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
1116 KB |
Output is correct |
7 |
Correct |
163 ms |
22040 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
7 ms |
1112 KB |
Output is correct |
13 |
Correct |
168 ms |
22020 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
600 KB |
Output is correct |
17 |
Correct |
76 ms |
8280 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
41 ms |
5744 KB |
Output is correct |
21 |
Correct |
160 ms |
22036 KB |
Output is correct |
22 |
Correct |
157 ms |
22044 KB |
Output is correct |
23 |
Correct |
169 ms |
22152 KB |
Output is correct |
24 |
Correct |
160 ms |
22100 KB |
Output is correct |
25 |
Correct |
64 ms |
8220 KB |
Output is correct |
26 |
Correct |
62 ms |
8276 KB |
Output is correct |
27 |
Correct |
182 ms |
22036 KB |
Output is correct |
28 |
Correct |
158 ms |
22100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Too few ways to get from 0 to 1, should be 2 found 1 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
1116 KB |
Output is correct |
7 |
Correct |
163 ms |
22040 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
7 ms |
1112 KB |
Output is correct |
13 |
Correct |
168 ms |
22020 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
600 KB |
Output is correct |
17 |
Correct |
76 ms |
8280 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
41 ms |
5744 KB |
Output is correct |
21 |
Correct |
160 ms |
22036 KB |
Output is correct |
22 |
Correct |
157 ms |
22044 KB |
Output is correct |
23 |
Correct |
169 ms |
22152 KB |
Output is correct |
24 |
Correct |
160 ms |
22100 KB |
Output is correct |
25 |
Correct |
64 ms |
8220 KB |
Output is correct |
26 |
Correct |
62 ms |
8276 KB |
Output is correct |
27 |
Correct |
182 ms |
22036 KB |
Output is correct |
28 |
Correct |
158 ms |
22100 KB |
Output is correct |
29 |
Correct |
1 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 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
1116 KB |
Output is correct |
7 |
Correct |
163 ms |
22040 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
7 ms |
1112 KB |
Output is correct |
13 |
Correct |
168 ms |
22020 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
600 KB |
Output is correct |
17 |
Correct |
76 ms |
8280 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
41 ms |
5744 KB |
Output is correct |
21 |
Correct |
160 ms |
22036 KB |
Output is correct |
22 |
Correct |
157 ms |
22044 KB |
Output is correct |
23 |
Correct |
169 ms |
22152 KB |
Output is correct |
24 |
Correct |
160 ms |
22100 KB |
Output is correct |
25 |
Correct |
64 ms |
8220 KB |
Output is correct |
26 |
Correct |
62 ms |
8276 KB |
Output is correct |
27 |
Correct |
182 ms |
22036 KB |
Output is correct |
28 |
Correct |
158 ms |
22100 KB |
Output is correct |
29 |
Correct |
1 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 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |