// I can do all things through Christ who strengthens me
// Philippians 4:13
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
#define REP(i, j, k) for (int i = j; i < (k); i++)
#define RREP(i, j, k) for (int i = j; i >= (k); i--)
template <class T>
inline bool mnto(T &a, const T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T &a, const T b) {return a < b ? a = b, 1 : 0;}
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int) x.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef tuple<int, int, int> iii;
#ifndef DEBUG
#define cerr if (0) cerr
#endif
const int INF = 1000000005;
const ll LINF = 1000000000000000005;
const int MAXN = 1005;
int n;
vector<vi> g;
vector<vi> ans;
bool vis[MAXN];
bool incyc[MAXN];
bool solve(vi comp) {
if (SZ(comp) == 1) {
return 1;
}
vi cyc, line;
for (int i : comp) {
bool all2 = 1;
for (int j : comp) {
if (i == j) {
continue;
}
if (g[i][j] != 2) {
all2 = 0;
break;
}
}
if (all2) {
cyc.pb(i);
incyc[i] = 1;
} else {
line.pb(i);
}
}
for (int i : line) {
for (int j : comp) {
if (j == i) {
continue;
}
if (incyc[j]) {
if (g[i][j] != 2) {
return 0;
}
} else {
if (g[i][j] != 1) {
return 0;
}
}
}
}
if (SZ(cyc) <= 1) {
return 0;
}
if (line.empty()) {
if (SZ(cyc) <= 2) {
return 0;
}
REP (i, 0, SZ(cyc)) {
ans[cyc[i]][cyc[(i + 1) % SZ(cyc)]] = 1;
ans[cyc[(i + 1) % SZ(cyc)]][cyc[i]] = 1;
}
return 1;
}
REP (i, 0, SZ(line) - 1) {
ans[line[i]][line[i + 1]] = 1;
ans[line[i + 1]][line[i]] = 1;
}
REP (i, 0, SZ(cyc) - 1) {
ans[cyc[i]][cyc[i + 1]] = 1;
ans[cyc[i + 1]][cyc[i]] = 1;
}
ans[line[0]][cyc[0]] = 1;
ans[cyc[0]][line[0]] = 1;
ans[line[0]][cyc.back()] = 1;
ans[cyc.back()][line[0]] = 1;
return 1;
}
int construct(vector<vi> p) {
n = SZ(p);
ans = vector<vi>(n, vi(n, 0));
g = p;
REP (i, 0, n) {
REP (j, 0, n) {
if (g[i][j] == 3) {
return 0;
}
}
}
REP (i, 0, n) {
if (vis[i]) {
continue;
}
vi comp;
REP (j, 0, n) {
if (g[i][j]) {
comp.pb(j);
}
}
for (int j : comp) {
vis[j] = 1;
REP (k, 0, n) {
if ((g[j][k] > 0) != (g[i][k] > 0)) {
return 0;
}
}
}
if (!solve(comp)) {
return 0;
}
}
build(ans);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Answer gives possible 0 while actual possible 1 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Answer gives possible 0 while actual possible 1 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
7 ms |
1364 KB |
Output is correct |
9 |
Correct |
154 ms |
27920 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1364 KB |
Output is correct |
13 |
Correct |
157 ms |
27892 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
980 KB |
Output is correct |
17 |
Correct |
66 ms |
17960 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
38 ms |
7224 KB |
Output is correct |
22 |
Correct |
156 ms |
28120 KB |
Output is correct |
23 |
Correct |
156 ms |
27852 KB |
Output is correct |
24 |
Correct |
161 ms |
27920 KB |
Output is correct |
25 |
Correct |
62 ms |
17996 KB |
Output is correct |
26 |
Correct |
63 ms |
18040 KB |
Output is correct |
27 |
Correct |
152 ms |
27928 KB |
Output is correct |
28 |
Correct |
162 ms |
27980 KB |
Output is correct |
29 |
Correct |
63 ms |
17996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 0 while actual possible 1 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Answer gives possible 0 while actual possible 1 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Answer gives possible 0 while actual possible 1 |
3 |
Halted |
0 ms |
0 KB |
- |