#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define ff first
#define ss second
#define pb push_back
//
const int mxN = 1001;
vector<vector<int>> paths;
int n;
bool vis[mxN];
void resetvis() {
for (int i = 0; i < n; i++) vis[i] = false;
}
vector<vector<int>> components;
vector<int> curcomponent;
void dfs(int u, int tar) {
curcomponent.pb(u);
vis[u] = true;
for (int v = 0; v < n; v++) {
if (u != v && 1 <= paths[u][v] && paths[u][v] <= tar && !vis[v]) {
dfs(v, tar);
}
}
}
int rep[mxN];
int repcnt = 1;
bool fullsol() {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (paths[i][j] == 3) return false;
}
}
for (int i = 0; i < n; i++) {
if (!vis[i]) {
dfs(i, 2);
for (int &x : curcomponent) rep[x] = repcnt;
repcnt++;
components.pb(curcomponent);
curcomponent.clear();
}
}
for (int u = 0; u < n; u++) {
for (int v = 0; v < n; v++) {
if (rep[u] == rep[v] && paths[u][v] == 0) return false;
if (rep[u] != rep[v] && paths[u][v] != 0) return false;
}
}
for (int i = 0; i < n; i++) rep[i] = 0;
repcnt = 1;
resetvis();
vector<vector<int>> ans(n);
for (int i = 0; i < n; i++) ans[i].resize(n, 0);
vector<vector<int>> decomp;
for (vector<int> &cur : components) {
decomp.clear();
for (int &u : cur) {
for (int &v : cur) {
if (u == v) continue;
if (!vis[u] && paths[u][v] == 1) {
dfs(u, 1);
for (int &x : curcomponent) rep[x] = repcnt;
repcnt++;
decomp.pb(curcomponent);
curcomponent.clear();
break;
}
}
if (!vis[u]) {
decomp.pb({u});
rep[u] = repcnt++;
vis[u] = true;
}
}
// cerr << "debug rep: ";
// for (int i = 0; i < n; i++) cerr << rep[i] << ' ';
// cerr << endl;
for (int &u : cur) {
for (int &v : cur) {
if (paths[u][v] != 1 + (rep[u] != rep[v])) return false;
}
}
for (vector<int> &process : decomp) {
if (process.size() >= 2) {
for (int i = 1; i < int(process.size()); i++) {
ans[process[i - 1]][process[i]] = 1;
}
}
}
if (decomp.size() >= 3) {
for (int i = 1; i < int(decomp.size()); i++) {
ans[decomp[i - 1][0]][decomp[i][0]] = 1;
}
ans[decomp.front()[0]][decomp.back()[0]] = 1;
} else if (decomp.size() == 2) return false;
}
for (int u = 0; u < n; u++) {
for (int v = 0; v < n; v++) {
ans[u][v] |= ans[v][u];
ans[v][u] |= ans[u][v];
}
}
build(ans);
return true;
}
int construct(vector<vector<int>> p) {
n = p.size(); paths = p;
return fullsol();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 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 |
8 ms |
1364 KB |
Output is correct |
7 |
Correct |
187 ms |
26072 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 |
0 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 |
8 ms |
1364 KB |
Output is correct |
7 |
Correct |
187 ms |
26072 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
1348 KB |
Output is correct |
13 |
Correct |
186 ms |
25988 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
92 ms |
12180 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
51 ms |
6740 KB |
Output is correct |
21 |
Correct |
199 ms |
25964 KB |
Output is correct |
22 |
Correct |
196 ms |
25996 KB |
Output is correct |
23 |
Correct |
203 ms |
25932 KB |
Output is correct |
24 |
Correct |
212 ms |
26140 KB |
Output is correct |
25 |
Correct |
76 ms |
12052 KB |
Output is correct |
26 |
Correct |
96 ms |
12052 KB |
Output is correct |
27 |
Correct |
194 ms |
26000 KB |
Output is correct |
28 |
Correct |
200 ms |
26060 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 |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
308 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
11 ms |
1420 KB |
Output is correct |
9 |
Correct |
187 ms |
27908 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
304 KB |
Output is correct |
12 |
Correct |
9 ms |
1344 KB |
Output is correct |
13 |
Correct |
185 ms |
27948 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
852 KB |
Output is correct |
17 |
Correct |
91 ms |
14092 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
300 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
50 ms |
7156 KB |
Output is correct |
22 |
Correct |
184 ms |
27852 KB |
Output is correct |
23 |
Correct |
194 ms |
27908 KB |
Output is correct |
24 |
Correct |
188 ms |
27956 KB |
Output is correct |
25 |
Correct |
89 ms |
18056 KB |
Output is correct |
26 |
Correct |
75 ms |
14080 KB |
Output is correct |
27 |
Correct |
181 ms |
27912 KB |
Output is correct |
28 |
Correct |
195 ms |
28056 KB |
Output is correct |
29 |
Correct |
77 ms |
18044 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 |
52 ms |
7256 KB |
Output is correct |
5 |
Correct |
201 ms |
27116 KB |
Output is correct |
6 |
Correct |
185 ms |
27084 KB |
Output is correct |
7 |
Correct |
215 ms |
27068 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
56 ms |
7208 KB |
Output is correct |
10 |
Correct |
211 ms |
27260 KB |
Output is correct |
11 |
Correct |
198 ms |
27104 KB |
Output is correct |
12 |
Correct |
206 ms |
27148 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
300 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
51 ms |
7160 KB |
Output is correct |
17 |
Correct |
188 ms |
27076 KB |
Output is correct |
18 |
Correct |
200 ms |
27064 KB |
Output is correct |
19 |
Correct |
197 ms |
27072 KB |
Output is correct |
20 |
Correct |
188 ms |
27168 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 |
0 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 |
8 ms |
1364 KB |
Output is correct |
7 |
Correct |
187 ms |
26072 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
1348 KB |
Output is correct |
13 |
Correct |
186 ms |
25988 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
92 ms |
12180 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
51 ms |
6740 KB |
Output is correct |
21 |
Correct |
199 ms |
25964 KB |
Output is correct |
22 |
Correct |
196 ms |
25996 KB |
Output is correct |
23 |
Correct |
203 ms |
25932 KB |
Output is correct |
24 |
Correct |
212 ms |
26140 KB |
Output is correct |
25 |
Correct |
76 ms |
12052 KB |
Output is correct |
26 |
Correct |
96 ms |
12052 KB |
Output is correct |
27 |
Correct |
194 ms |
26000 KB |
Output is correct |
28 |
Correct |
200 ms |
26060 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
308 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
11 ms |
1420 KB |
Output is correct |
37 |
Correct |
187 ms |
27908 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
304 KB |
Output is correct |
40 |
Correct |
9 ms |
1344 KB |
Output is correct |
41 |
Correct |
185 ms |
27948 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
4 ms |
852 KB |
Output is correct |
45 |
Correct |
91 ms |
14092 KB |
Output is correct |
46 |
Correct |
0 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
300 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
50 ms |
7156 KB |
Output is correct |
50 |
Correct |
184 ms |
27852 KB |
Output is correct |
51 |
Correct |
194 ms |
27908 KB |
Output is correct |
52 |
Correct |
188 ms |
27956 KB |
Output is correct |
53 |
Correct |
89 ms |
18056 KB |
Output is correct |
54 |
Correct |
75 ms |
14080 KB |
Output is correct |
55 |
Correct |
181 ms |
27912 KB |
Output is correct |
56 |
Correct |
195 ms |
28056 KB |
Output is correct |
57 |
Correct |
77 ms |
18044 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
212 KB |
Output is correct |
60 |
Correct |
4 ms |
852 KB |
Output is correct |
61 |
Correct |
81 ms |
14128 KB |
Output is correct |
62 |
Correct |
1 ms |
212 KB |
Output is correct |
63 |
Correct |
1 ms |
300 KB |
Output is correct |
64 |
Correct |
1 ms |
308 KB |
Output is correct |
65 |
Correct |
51 ms |
7184 KB |
Output is correct |
66 |
Correct |
72 ms |
14076 KB |
Output is correct |
67 |
Correct |
70 ms |
14028 KB |
Output is correct |
68 |
Correct |
76 ms |
14072 KB |
Output is correct |
69 |
Correct |
96 ms |
18044 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 |
0 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 |
8 ms |
1364 KB |
Output is correct |
7 |
Correct |
187 ms |
26072 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
1348 KB |
Output is correct |
13 |
Correct |
186 ms |
25988 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
92 ms |
12180 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
51 ms |
6740 KB |
Output is correct |
21 |
Correct |
199 ms |
25964 KB |
Output is correct |
22 |
Correct |
196 ms |
25996 KB |
Output is correct |
23 |
Correct |
203 ms |
25932 KB |
Output is correct |
24 |
Correct |
212 ms |
26140 KB |
Output is correct |
25 |
Correct |
76 ms |
12052 KB |
Output is correct |
26 |
Correct |
96 ms |
12052 KB |
Output is correct |
27 |
Correct |
194 ms |
26000 KB |
Output is correct |
28 |
Correct |
200 ms |
26060 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
308 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
11 ms |
1420 KB |
Output is correct |
37 |
Correct |
187 ms |
27908 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
304 KB |
Output is correct |
40 |
Correct |
9 ms |
1344 KB |
Output is correct |
41 |
Correct |
185 ms |
27948 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
4 ms |
852 KB |
Output is correct |
45 |
Correct |
91 ms |
14092 KB |
Output is correct |
46 |
Correct |
0 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
300 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
50 ms |
7156 KB |
Output is correct |
50 |
Correct |
184 ms |
27852 KB |
Output is correct |
51 |
Correct |
194 ms |
27908 KB |
Output is correct |
52 |
Correct |
188 ms |
27956 KB |
Output is correct |
53 |
Correct |
89 ms |
18056 KB |
Output is correct |
54 |
Correct |
75 ms |
14080 KB |
Output is correct |
55 |
Correct |
181 ms |
27912 KB |
Output is correct |
56 |
Correct |
195 ms |
28056 KB |
Output is correct |
57 |
Correct |
77 ms |
18044 KB |
Output is correct |
58 |
Correct |
0 ms |
212 KB |
Output is correct |
59 |
Correct |
0 ms |
212 KB |
Output is correct |
60 |
Correct |
1 ms |
212 KB |
Output is correct |
61 |
Correct |
52 ms |
7256 KB |
Output is correct |
62 |
Correct |
201 ms |
27116 KB |
Output is correct |
63 |
Correct |
185 ms |
27084 KB |
Output is correct |
64 |
Correct |
215 ms |
27068 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
56 ms |
7208 KB |
Output is correct |
67 |
Correct |
211 ms |
27260 KB |
Output is correct |
68 |
Correct |
198 ms |
27104 KB |
Output is correct |
69 |
Correct |
206 ms |
27148 KB |
Output is correct |
70 |
Correct |
0 ms |
212 KB |
Output is correct |
71 |
Correct |
1 ms |
300 KB |
Output is correct |
72 |
Correct |
1 ms |
212 KB |
Output is correct |
73 |
Correct |
51 ms |
7160 KB |
Output is correct |
74 |
Correct |
188 ms |
27076 KB |
Output is correct |
75 |
Correct |
200 ms |
27064 KB |
Output is correct |
76 |
Correct |
197 ms |
27072 KB |
Output is correct |
77 |
Correct |
188 ms |
27168 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
1 ms |
212 KB |
Output is correct |
80 |
Correct |
4 ms |
852 KB |
Output is correct |
81 |
Correct |
81 ms |
14128 KB |
Output is correct |
82 |
Correct |
1 ms |
212 KB |
Output is correct |
83 |
Correct |
1 ms |
300 KB |
Output is correct |
84 |
Correct |
1 ms |
308 KB |
Output is correct |
85 |
Correct |
51 ms |
7184 KB |
Output is correct |
86 |
Correct |
72 ms |
14076 KB |
Output is correct |
87 |
Correct |
70 ms |
14028 KB |
Output is correct |
88 |
Correct |
76 ms |
14072 KB |
Output is correct |
89 |
Correct |
96 ms |
18044 KB |
Output is correct |
90 |
Correct |
0 ms |
212 KB |
Output is correct |
91 |
Correct |
1 ms |
304 KB |
Output is correct |
92 |
Correct |
6 ms |
852 KB |
Output is correct |
93 |
Correct |
75 ms |
14076 KB |
Output is correct |
94 |
Correct |
1 ms |
212 KB |
Output is correct |
95 |
Correct |
1 ms |
212 KB |
Output is correct |
96 |
Correct |
1 ms |
212 KB |
Output is correct |
97 |
Correct |
18 ms |
3668 KB |
Output is correct |
98 |
Correct |
72 ms |
14076 KB |
Output is correct |
99 |
Correct |
86 ms |
14080 KB |
Output is correct |
100 |
Correct |
68 ms |
14072 KB |
Output is correct |
101 |
Correct |
68 ms |
14084 KB |
Output is correct |
102 |
Correct |
73 ms |
14004 KB |
Output is correct |
103 |
Correct |
72 ms |
14076 KB |
Output is correct |
104 |
Correct |
74 ms |
14084 KB |
Output is correct |
105 |
Correct |
78 ms |
14004 KB |
Output is correct |