#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,N) for(long long i = 0; (i) < (N); (i)++)
#define FORS(i,v,N) for(long long i = v; (i) < (N); (i)++)
#define FORI(i,v,N,inc) for(long long i = v; (i) < (N); (i)+=(inc))
#define NL '\n'
#define EL cout << NL
#define PRINTV(v) for(auto a:(v)) {cout << a << " ";};EL
#define PRINTVV(v) for(auto a:(v)) {PRINTV(a);}
typedef long long ll;
typedef vector<ll> VL;
typedef vector<VL> VLL;
typedef pair<ll,ll> PL;
typedef vector<PL> VPL;
typedef vector<VPL> VVPL;
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
std::vector<std::vector<int>> answer;
for (int i = 0; i < n; i++) {
std::vector<int> row;
row.resize(n);
answer.push_back(row);
}
vector<bool> visited(n,0);
FOR(s,n) {
if (!visited[s]) {
vector<int> branch;
vector<int> cycle;
vector<int> comp;
vector<bool> incycle(n,false);
vector<int> adress(n,-1);
stack<pair<int,int>> st;
int bnum = 0;
st.push({s,0});
while(!st.empty()) {
int u = st.top().first;
int t = st.top().second;
st.pop();
if (visited[u]) continue;
//cout << u << " " << t << NL;
visited[u] = true;
bool is_cycle = true;
FOR(v,n) {
if (v == u) continue;
if (p[u][v] >= 1) {
is_cycle = is_cycle && (p[u][v] == 2);
int type = 0;
if (p[u][v] == 1) {
if (adress[v] > 0 && adress[v] < t) type = t = adress[v];
if (t > 0) type = t;
else if (adress[v] > 0) type = t = adress[v];
else t = type = ++bnum;
}
st.push({v,type});
}
}
if (is_cycle) {
cycle.push_back(u);
incycle[u] = true;
}
else branch.push_back(u);
adress[u] = t;
comp.push_back(u);
}
//PRINTV(branch);
//PRINTV(cycle);
//PRINTV(adress);
//PRINTV(incycle);
for (auto u: comp) {
for (auto v: comp) {
if (p[u][v] == 0) return 0;
if (u != v && p[u][v] != 2 && (adress[u] != adress[v] || incycle[u] || incycle[v])) {
return 0;
}
if (u != v && p[u][v] != 1 && (adress[u] == adress[v] && !(incycle[u] || incycle[v]))) {
return 0;
}
}
}
for (auto u: branch) {
FOR(v,n) {
if (p[u][v] == 2 && !incycle[v]) {
return 0;
}
}
}
int prev_u = -1;
for(auto u: branch) {
if (prev_u >= 0) {
answer[u][prev_u] = answer[prev_u][u] = 1;
}
prev_u = u;
}
int prev_v = prev_u;
int first_c = prev_u;
for (auto v: cycle) {
if (prev_v >= 0) answer[v][prev_v] = answer[prev_v][v] = 1;
prev_v = v;
if (first_c == -1) first_c = v;
}
if (prev_v != first_c) answer[first_c][prev_v] = answer[prev_v][first_c] = 1;
}
}
build(answer);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
1248 KB |
Output is correct |
7 |
Correct |
163 ms |
23972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
1248 KB |
Output is correct |
7 |
Correct |
163 ms |
23972 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 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 |
1236 KB |
Output is correct |
13 |
Correct |
154 ms |
23924 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
924 KB |
Output is correct |
17 |
Correct |
75 ms |
16168 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
300 KB |
Output is correct |
20 |
Correct |
38 ms |
6252 KB |
Output is correct |
21 |
Correct |
180 ms |
24004 KB |
Output is correct |
22 |
Correct |
150 ms |
23936 KB |
Output is correct |
23 |
Correct |
200 ms |
23920 KB |
Output is correct |
24 |
Correct |
153 ms |
23980 KB |
Output is correct |
25 |
Correct |
63 ms |
14068 KB |
Output is correct |
26 |
Correct |
60 ms |
14080 KB |
Output is correct |
27 |
Correct |
162 ms |
24000 KB |
Output is correct |
28 |
Correct |
150 ms |
24012 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 |
Incorrect |
1 ms |
340 KB |
Answer gives possible 1 while actual possible 0 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
300 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
39 ms |
6192 KB |
Output is correct |
5 |
Correct |
152 ms |
24004 KB |
Output is correct |
6 |
Correct |
151 ms |
23968 KB |
Output is correct |
7 |
Correct |
160 ms |
23920 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
38 ms |
6252 KB |
Output is correct |
10 |
Correct |
155 ms |
24008 KB |
Output is correct |
11 |
Correct |
149 ms |
23952 KB |
Output is correct |
12 |
Correct |
159 ms |
23916 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Incorrect |
15 ms |
3668 KB |
Answer gives possible 0 while actual possible 1 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
1248 KB |
Output is correct |
7 |
Correct |
163 ms |
23972 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 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 |
1236 KB |
Output is correct |
13 |
Correct |
154 ms |
23924 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
924 KB |
Output is correct |
17 |
Correct |
75 ms |
16168 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
300 KB |
Output is correct |
20 |
Correct |
38 ms |
6252 KB |
Output is correct |
21 |
Correct |
180 ms |
24004 KB |
Output is correct |
22 |
Correct |
150 ms |
23936 KB |
Output is correct |
23 |
Correct |
200 ms |
23920 KB |
Output is correct |
24 |
Correct |
153 ms |
23980 KB |
Output is correct |
25 |
Correct |
63 ms |
14068 KB |
Output is correct |
26 |
Correct |
60 ms |
14080 KB |
Output is correct |
27 |
Correct |
162 ms |
24000 KB |
Output is correct |
28 |
Correct |
150 ms |
24012 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Incorrect |
1 ms |
340 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
1248 KB |
Output is correct |
7 |
Correct |
163 ms |
23972 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 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 |
1236 KB |
Output is correct |
13 |
Correct |
154 ms |
23924 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
924 KB |
Output is correct |
17 |
Correct |
75 ms |
16168 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
300 KB |
Output is correct |
20 |
Correct |
38 ms |
6252 KB |
Output is correct |
21 |
Correct |
180 ms |
24004 KB |
Output is correct |
22 |
Correct |
150 ms |
23936 KB |
Output is correct |
23 |
Correct |
200 ms |
23920 KB |
Output is correct |
24 |
Correct |
153 ms |
23980 KB |
Output is correct |
25 |
Correct |
63 ms |
14068 KB |
Output is correct |
26 |
Correct |
60 ms |
14080 KB |
Output is correct |
27 |
Correct |
162 ms |
24000 KB |
Output is correct |
28 |
Correct |
150 ms |
24012 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Incorrect |
1 ms |
340 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |