#include "train.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
const int INF = 1e9+10;
const ll LINF = 1e18+10;
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define mk make_pair
#define pb push_back
#define f first
#define s second
int t, grau[5005], at_grau[5005];
bool valid[5005], B[5005], R[5005];
vector<int> edges[5005];
void dfs(int x) {
for(int viz : edges[x]) {
if(R[viz]) continue;
at_grau[viz]--;
if(B[viz] and !valid[viz]) valid[viz] = 1, dfs(viz);
if(at_grau[viz] == 0 and !valid[viz]) valid[viz] = 1, dfs(viz);
}
}
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
int n = sz(a), m = sz(u);
vector<int> ans(n,1);
for(int i = 0; i < m; i++) edges[v[i]].pb(u[i]), grau[u[i]]++;
for(int i = 0; i < n; i++) B[i] = !a[i], R[i] = r[i];
queue<int> fila;
for(int i = 0; i < n; i++) {
if(r[i]) continue;
for(int j = 0; j < n; j++) at_grau[j] = grau[i], valid[j] = 0;
dfs(i);
if(valid[i]) fila.push(i);
}
while(!fila.empty()) {
int x = fila.front();
fila.pop();
if(!ans[x]) continue;
ans[x] = 0;
for(int viz : edges[x]) {
grau[viz]--;
if(grau[viz] == 0) fila.push(viz);
else if(!a[viz]) fila.push(viz);
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
860 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 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Incorrect |
1 ms |
348 KB |
3rd lines differ - on the 4th token, expected: '0', found: '1' |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
143 ms |
1628 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 |
Correct |
5 ms |
1112 KB |
Output is correct |
2 |
Correct |
79 ms |
1116 KB |
Output is correct |
3 |
Correct |
112 ms |
1392 KB |
Output is correct |
4 |
Correct |
32 ms |
1380 KB |
Output is correct |
5 |
Correct |
199 ms |
1380 KB |
Output is correct |
6 |
Correct |
191 ms |
1440 KB |
Output is correct |
7 |
Correct |
156 ms |
1380 KB |
Output is correct |
8 |
Correct |
99 ms |
1380 KB |
Output is correct |
9 |
Correct |
6 ms |
1112 KB |
Output is correct |
10 |
Correct |
9 ms |
1368 KB |
Output is correct |
11 |
Correct |
6 ms |
1372 KB |
Output is correct |
12 |
Correct |
7 ms |
1368 KB |
Output is correct |
13 |
Correct |
388 ms |
1516 KB |
Output is correct |
14 |
Correct |
207 ms |
1368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
770 ms |
1560 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
860 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |