%:include "train.h"
%:include <bits/stdc++.h>
%:define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
%:define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
const int N = 5050;
bool rem[N];
bool owner[N];
bool charg[N];
int deg[N];
vector<int> T[N];
vector<int> V;
void remove(const vector<int> &vec)
{
for (int v : vec)
rem[v] = 1;
Loop (i,0,V.size()) {
if (rem[V[i]]) {
swap(V[i], V.back());
V.pop_back();
--i;
}
}
for (int v : V) {
Loop (i,0,T[v].size()) {
if (rem[T[v][i]]) {
swap(T[v][i], T[v].back());
T[v].pop_back();
--i;
}
}
}
}
int cnt[N];
bool vis[N];
void dfs(int v, bool o)
{
vis[v] = 1;
for (int u : T[v]) {
++cnt[u];
if (!vis[u] && (owner[u] == o || cnt[u] == deg[u]))
dfs(u, o);
}
}
vector<int> f(const vector<int> &vec, bool o)
{
for (int v : vec) {
if (!rem[v] && !vis[v])
dfs(v, o);
}
vector<int> ans;
for (int v : V) {
if (vis[v])
ans.push_back(v);
vis[v] = 0;
cnt[v] = 0;
}
return ans;
}
vector<int> cmpl(const vector<int> &vec)
{
vector<int> ans;
static bool a[N];
for (int v : vec)
a[v] = 1;
for (int v : V) {
if (!a[v])
ans.push_back(v);
}
for (int v : vec)
a[v] = 0;
return ans;
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> uu, std::vector<int> vv)
{
int n = a.size();
V.resize(n);
iota(V.begin(), V.end(), 0);
vector<int> charg;
Loop (i,0,n) {
owner[i] = a[i];
if (r[i])
charg.push_back(i);
}
Loop (i,0,vv.size()) {
int v = vv[i], u = uu[i];
deg[v]++;
T[u].push_back(v);
}
vector<int> ans;
for (;;) {
auto vec = f(charg, 1);
if (vec.size() == V.size()) {
ans = V;
break;
}
if (vec.size() == 0)
break;
auto vec2 = f(cmpl(vec), 0);
remove(vec2);
}
vector<int> res(n);
for (int v : ans)
res[v] = 1;
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
852 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
1272 KB |
Output is correct |
2 |
Correct |
34 ms |
1268 KB |
Output is correct |
3 |
Correct |
79 ms |
1320 KB |
Output is correct |
4 |
Incorrect |
6 ms |
1492 KB |
3rd lines differ - on the 13th token, expected: '1', found: '0' |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
1236 KB |
3rd lines differ - on the 2nd token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
1236 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
852 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |