#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "train.h"
struct SCCF {
int n;
VVI gpa;
VVI trans;
VI vis;
VVI comp;
VI group;
VI order;
void dfs1(int u) {
vis[u] = true;
for (int v : gpa[u]) if (!vis[v]) dfs1(v);
order.pb(u);
}
void dfs2(int u) {
comp.back().pb(u);
group[u] = comp.size()-1;
vis[u] = true;
for (int v : trans[u]) if (!vis[v]) dfs2(v);
}
tuple<VVI, VVI, VI, VI> operator()(VVI& GPA) {
gpa = GPA;
n = gpa.size();
trans = VVI(n);
rep(u, n) for (int v : gpa[u]) trans[v].pb(u);
vis = VI(n);
rep(u, n) if (!vis[u]) dfs1(u);
reverse(all(order));
vis = VI(n);
group = VI(n);
comp = VVI();
for (int u : order) if (!vis[u]) {
comp.pb(VI());
dfs2(u);
}
VVI gpb(comp.size());
VI cycle(comp.size());
rep(u, n) for (int v : gpa[u]) if (group[u] != group[v]) {
gpb[group[u]].pb(group[v]);
} else cycle[group[u]] = true;
return make_tuple(gpb, comp, group, cycle);
}
} SCC;
namespace TEST1 {
bool check(VI U, VI V) {
rep(i, U.size()) if (V[i] != U[i] && V[i] != U[i]+1) return false;
return true;
}
VI solve(VVI gp, VI owner, VI charge) {
int n = gp.size();
VI ans(n);
reprl(u, n-1, 0) {
if (gp[u].size() == 2) {
if (owner[u] == 1) {
ans[u] = 0;
if (charge[u] == 1) ans[u] = 1;
else for (int v : gp[u]) if (v != u) {
if (ans[v] == 1) ans[u] = 1;
}
} else {
ans[u] = 1;
if (charge[u] == 0) ans[u] = 0;
else for (int v : gp[u]) if (v != u) {
if (ans[v] == 0) ans[u] = 0;
}
}
} else if (gp[u].size()) {
if (gp[u][0] == u) {
ans[u] = (charge[u]);
} else {
ans[u] = ans[gp[u][0]];
}
}
}
return ans;
}
};
namespace TEST2 {
};
namespace TEST3 {
bool check(VI owner) {
for (int x : owner) if (x == 0) return false;
return true;
}
VI solve(VVI GP, VI OWNER, VI charge) {
int n = GP.size();
auto[gp, comp, group, cycle] = SCC(GP);
int g = gp.size();
VI ansg(g);
rep(u, n) if (charge[u] && cycle[group[u]]) {
ansg[group[u]] = true;
}
reprl(u, g-1, 0) {
for (int v : gp[u]) {
ansg[u] |= ansg[v];
}
}
VI ans(n);
rep(u, n) ans[u] = ansg[group[u]];
return ans;
}
};
namespace TEST4 {
bool check(VI owner) {
for (int x : owner) if (x == 1) return false;
return true;
}
VI solve(VVI GP, VI OWNER, VI charge) {
int n = GP.size();
VI krox(n);
if (true) {
VVI gpa(n);
rep(u, n) for (int v : GP[u]) {
if (charge[u] || charge[v]) continue;
gpa[u].pb(v);
}
auto[_, __, group, cycle] = SCC(gpa);
rep(u, n) if (!charge[u]) {
if (cycle[group[u]]) krox[u] = true;
}
}
auto[gp, comp, group, cycle] = SCC(GP);
int g = gp.size();
VI ansg(g);
rep(u, n) if (krox[u]) {
ansg[group[u]] = true;
}
reprl(u, g-1, 0) {
for (int v : gp[u]) {
ansg[u] |= ansg[v];
}
}
VI ans(n);
rep(u, n) ans[u] = ansg[group[u]];
for (int& x : ans) x = !x;
return ans;
}
};
VI who_wins(VI owner, VI charge, VI U, VI V) {
int n = owner.size();
int m = U.size();
VVI gp(n);
rep(i, m) gp[U[i]].pb(V[i]);
if (TEST1::check(U, V)) return TEST1::solve(gp, owner, charge);
if (TEST3::check(owner)) return TEST3::solve(gp, owner, charge);
if (TEST4::check(owner)) return TEST4::solve(gp, owner, charge);
return {3, 1, 4};
}
Compilation message
train.cpp: In function 'VI TEST3::solve(VVI, VI, VI)':
train.cpp:125:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
125 | auto[gp, comp, group, cycle] = SCC(GP);
| ^
train.cpp: In function 'VI TEST4::solve(VVI, VI, VI)':
train.cpp:155:17: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
155 | auto[_, __, group, cycle] = SCC(gpa);
| ^
train.cpp:160:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
160 | auto[gp, comp, group, cycle] = SCC(GP);
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1116 KB |
Output is correct |
2 |
Correct |
3 ms |
1216 KB |
Output is correct |
3 |
Correct |
3 ms |
1116 KB |
Output is correct |
4 |
Correct |
4 ms |
1056 KB |
Output is correct |
5 |
Correct |
3 ms |
1368 KB |
Output is correct |
6 |
Correct |
3 ms |
1216 KB |
Output is correct |
7 |
Correct |
3 ms |
1116 KB |
Output is correct |
8 |
Correct |
3 ms |
1300 KB |
Output is correct |
9 |
Correct |
3 ms |
1116 KB |
Output is correct |
10 |
Correct |
3 ms |
1112 KB |
Output is correct |
11 |
Correct |
3 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
WA in grader: Wrong returned array size |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
3648 KB |
Output is correct |
2 |
Correct |
10 ms |
3392 KB |
Output is correct |
3 |
Correct |
7 ms |
3280 KB |
Output is correct |
4 |
Correct |
7 ms |
2536 KB |
Output is correct |
5 |
Correct |
7 ms |
2624 KB |
Output is correct |
6 |
Correct |
7 ms |
2624 KB |
Output is correct |
7 |
Correct |
11 ms |
2368 KB |
Output is correct |
8 |
Correct |
7 ms |
2428 KB |
Output is correct |
9 |
Correct |
6 ms |
2376 KB |
Output is correct |
10 |
Correct |
6 ms |
2376 KB |
Output is correct |
11 |
Correct |
7 ms |
2584 KB |
Output is correct |
12 |
Correct |
7 ms |
3268 KB |
Output is correct |
13 |
Correct |
7 ms |
2444 KB |
Output is correct |
14 |
Correct |
7 ms |
2368 KB |
Output is correct |
15 |
Correct |
6 ms |
2368 KB |
Output is correct |
16 |
Correct |
6 ms |
2368 KB |
Output is correct |
17 |
Correct |
6 ms |
2368 KB |
Output is correct |
18 |
Correct |
9 ms |
3004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2648 KB |
Output is correct |
2 |
Correct |
9 ms |
3520 KB |
Output is correct |
3 |
Correct |
9 ms |
3628 KB |
Output is correct |
4 |
Correct |
8 ms |
3136 KB |
Output is correct |
5 |
Correct |
15 ms |
3792 KB |
Output is correct |
6 |
Correct |
14 ms |
3656 KB |
Output is correct |
7 |
Correct |
9 ms |
3684 KB |
Output is correct |
8 |
Correct |
9 ms |
3404 KB |
Output is correct |
9 |
Correct |
14 ms |
3232 KB |
Output is correct |
10 |
Correct |
9 ms |
2876 KB |
Output is correct |
11 |
Correct |
7 ms |
2872 KB |
Output is correct |
12 |
Correct |
8 ms |
2904 KB |
Output is correct |
13 |
Correct |
10 ms |
3136 KB |
Output is correct |
14 |
Correct |
16 ms |
3408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
1476 KB |
WA in grader: Wrong returned array size |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1116 KB |
Output is correct |
2 |
Correct |
3 ms |
1216 KB |
Output is correct |
3 |
Correct |
3 ms |
1116 KB |
Output is correct |
4 |
Correct |
4 ms |
1056 KB |
Output is correct |
5 |
Correct |
3 ms |
1368 KB |
Output is correct |
6 |
Correct |
3 ms |
1216 KB |
Output is correct |
7 |
Correct |
3 ms |
1116 KB |
Output is correct |
8 |
Correct |
3 ms |
1300 KB |
Output is correct |
9 |
Correct |
3 ms |
1116 KB |
Output is correct |
10 |
Correct |
3 ms |
1112 KB |
Output is correct |
11 |
Correct |
3 ms |
1116 KB |
Output is correct |
12 |
Incorrect |
1 ms |
348 KB |
WA in grader: Wrong returned array size |
13 |
Halted |
0 ms |
0 KB |
- |