#include "train.h"
#include <bits/stdc++.h>
using namespace std;
const int nx=5e3+5;
int n, cy[nx], pa[nx], vs[nx], f;
vector<int> d[nx], rv[nx], R(nx);
void dfs(int u, int rt)
{
vs[u]=1;
if (f) return;
for (auto v:d[u])
{
if (!f&&v==rt)
{
int tmp=u;
while (tmp!=rt) cy[tmp]=1, tmp=pa[tmp];
cy[rt]=1;
f=1;
return;
}
if (vs[v]||R[v]) continue;
pa[v]=u;
dfs(v, rt);
}
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
n=a.size();
for (int i=0; i<n; i++) R[i]=r[i];
for (int i=0; i<u.size(); i++) d[u[i]].push_back(v[i]), rv[v[i]].push_back(u[i]);
for (int i=0; i<n; i++)
{
if (!r[i])
{
f=0;
for (int j=0; j<n;j ++) vs[j]=0;
dfs(i, i);
}
}
vector<int> res(n, 1);
queue<int> q;
for (int i=0; i<n;i ++) vs[i]=0;
for (int i=0; i<n;i ++) if (cy[i]) q.push(i), vs[i]=1;
while (!q.empty())
{
auto cur=q.front();
q.pop();
res[cur]=0;
for (auto x:rv[cur]) if (!vs[x]) vs[x]=1,q.push(x);
}
return res;
}
Compilation message
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:34:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for (int i=0; i<u.size(); i++) d[u[i]].push_back(v[i]), rv[v[i]].push_back(u[i]);
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
1112 KB |
3rd lines differ - on the 14th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
604 KB |
3rd lines differ - on the 2nd token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
1808 KB |
Output is correct |
2 |
Correct |
32 ms |
1628 KB |
Output is correct |
3 |
Correct |
7 ms |
1624 KB |
Output is correct |
4 |
Incorrect |
328 ms |
1628 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1372 KB |
Output is correct |
2 |
Correct |
73 ms |
1432 KB |
Output is correct |
3 |
Correct |
100 ms |
1368 KB |
Output is correct |
4 |
Correct |
19 ms |
1368 KB |
Output is correct |
5 |
Correct |
264 ms |
1372 KB |
Output is correct |
6 |
Correct |
185 ms |
1368 KB |
Output is correct |
7 |
Correct |
187 ms |
1524 KB |
Output is correct |
8 |
Correct |
88 ms |
1496 KB |
Output is correct |
9 |
Correct |
4 ms |
1372 KB |
Output is correct |
10 |
Correct |
5 ms |
1372 KB |
Output is correct |
11 |
Correct |
5 ms |
1372 KB |
Output is correct |
12 |
Correct |
5 ms |
1432 KB |
Output is correct |
13 |
Correct |
297 ms |
1628 KB |
Output is correct |
14 |
Correct |
171 ms |
1368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
518 ms |
1700 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
1112 KB |
3rd lines differ - on the 14th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |