#include <bits/stdc++.h>
#include "train.h"
using namespace std;
const int MAXN = 5005;
vector<int> G[MAXN], Gt[MAXN], owner, fuel;
vector<int> res, viz, S;
vector<int> inset;
int N;
vector<int> who_wins( vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
owner = a, fuel = r;
for ( int i = 0; i < (int)u.size(); ++i ) {
G[u[i]].push_back(v[i]);
Gt[v[i]].push_back(u[i]);
}
N = a.size();
res.resize(N), S.resize(N);
queue<int> q;
viz.assign(N, 0);
inset.resize(N);
for ( int i = 0; i < N; ++i ) inset[i] = 1;
bool emp = false;
while ( !emp ) {
for ( int i = 0; i < N; ++i ) {
if ( fuel[i] && inset[i] ) {
q.push(i);
S[i] = 1;
}
}
while ( !q.empty() ) {
int u = q.front();
q.pop();
for ( auto v : Gt[u] ) {
++viz[v];
if ( inset[v] && !S[v] && owner[v] == 1 ) {
q.push(v);
S[v] = 1;
} else if ( inset[v] && !S[v] && owner[v] == 0 && viz[v] == (int)G[v].size() ) {
q.push(v);
S[v] = 1;
}
}
}
for ( int i = 0; i < N; ++i ) {
if ( inset[i] ) {
S[i] = 1 - S[i];
if ( S[i] ) q.push(i);
viz[i] = 0;
}
}
if ( q.empty() ) {
for ( int i = 0; i < N; ++i ) {
if ( inset[i] ) {
res[i] = 1 - S[i];
} else {
res[i] = S[i];
}
}
break;
}
while ( !q.empty() ) {
int u = q.front();
q.pop();
for ( auto v : Gt[u] ) {
++viz[v];
if ( inset[v] && !S[v] && owner[v] == 0 ) {
q.push(v);
S[v] = 1;
} else if ( inset[v] && !S[v] && owner[v] == 1 && viz[v] == (int)G[v].size() ) {
q.push(v);
S[v] = 1;
}
}
}
for ( int i = 0; i < N; ++i ) {
if ( S[i] ) inset[i] = 0;
}
}
return res;
}
/*
int main() {
int n, m;
assert(2 == scanf("%d %d", &n, &m));
vector<int> a(n), r(n), u(m), v(m);
for(int i = 0; i < n; i++)
assert(1 == scanf("%d", &a[i]));
for(int i = 0; i < n; i++)
assert(1 == scanf("%d", &r[i]));
for(int i = 0; i < m; i++)
scanf("%d", &u[i]);
for ( int i = 0; i < m; ++i ) {
scanf("%d", &v[i]);
}
vector<int> res = who_wins(a, r, u, v);
for(int i = 0; i < (int)res.size(); i++)
printf(i ? " %d" : "%d", res[i]);
printf("\n");
return 0;
}*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
1136 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
468 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
116 ms |
1504 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
1236 KB |
3rd lines differ - on the 696th token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
1492 KB |
3rd lines differ - on the 2nd token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
1136 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |