#include "train.h"
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <queue>
using namespace std;
const int N = 5e3 + 7;
int n, m;
unordered_set<int> R;
vector<int> g[N], g1[N];
vector<int> A;
void rev(vector<bool> &fi){
for (bool &&it : fi)
it = !it;
}
void Fw(int w, vector<bool> &fi){
static queue<int> q;
for (int i = 0; i < fi.size(); i++)
if (fi[i])
q.push(i);
while (!q.empty()){
auto it = q.front(); q.pop();
for (auto to : g1[it]){
if (fi[to])
continue;
if (A[to] == w || all_of(g[to].begin(), g[to].end(), [&](int x){return fi[x] == 1; }))
{
fi[to] = true;
q.push(to);
}
}
}
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
::n = a.size();
::A = a;
::m = u.size();
vector<int> res;
vector<bool> R;
for (auto it : r)
R.push_back(it);
for (int i = 0; i < m; ++i){
g[u[i]].push_back(v[i]);
g1[v[i]].push_back(u[i]);
}
while (true){
static vector<bool> X;
X = R;
Fw(1, X);
rev(X);
Fw(0, X);
int cnt = 0;
for (int i = 0; i < n; i++)
if (R[i] && X[i])
{
cnt++;
R[i] = false;
}
if (cnt == 0){
auto ans = vector<int>(n, 1);
for (int i = 0; i < n; i++)
if (X[i])
ans[i] = 0;
return ans;
}
}
return res;
}
Compilation message
train.cpp: In function 'void Fw(int, std::vector<bool>&)':
train.cpp:24:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < fi.size(); i++)
~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
1016 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
1016 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
1584 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
1584 KB |
3rd lines differ - on the 696th token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
1644 KB |
3rd lines differ - on the 2nd token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
1016 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |