#include "train.h"
#include <bits/stdc++.h>
using namespace std;
int n, m, dead[5000];
vector<int> E[5000], R[5000];
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v)
{
n = a.size(), m = u.size();
vector<int> ans(n, 1);
while (1)
{
for (int i = 0; i < n; i++)
E[i].clear(), R[i].clear();
for (int i = 0; i < m; i++)
if (!dead[i])
{
E[u[i]].emplace_back(v[i]);
E[v[i]].emplace_back(u[i]);
}
vector<int> req(n), vis(n, 0);
for (int i = 0; i < n; i++)
if (!dead[i])
{
if (a[i])
req[i] = 1;
else
req[i] = E[i].size();
}
queue<int> q;
for (int i = 0; i < n; i++)
if (!dead[i] && r[i])
{
vis[i] = 1;
q.emplace(i);
}
while (!q.empty())
{
int i = q.front();
q.pop();
for (auto j : R[i])
if(--req[j] == 0)
{
vis[j] = 1;
q.emplace(j);
}
}
for (int i = 0; i < n; i++)
if (!dead[i])
{
if (a[i])
req[i] = E[i].size();
else
req[i] = 1;
}
for (int i = 0; i < n; i++)
if(!dead[i] && !vis[i])
q.emplace(i);
if(q.empty())
break;
fill(vis.begin(), vis.end(), 0);
while (!q.empty())
{
int i = q.front();
ans[i] = 0, dead[i] = 1;
q.pop();
for (auto j : R[i])
if(--req[j] == 0)
q.emplace(j);
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
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 |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
468 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 |
Runtime error |
5 ms |
2132 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
5 ms |
1876 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
5 ms |
2140 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
- |