#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ii = pair<int, int>;
#define pb push_back
#define pp pop_back
#define ff first
#define ss second
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
int N, M, timer, tin[5001], low[5001];
vector<int> adj[5001], S;
bool vis[5001], Scc[5001], station[5001];
void dfs(int v) {
tin[v] = low[v] = timer++;
S.push_back(v); vis[v] = 1;
for(auto u : adj[v]) {
if(tin[u] == -1) dfs(u);
if(vis[u]) low[v] = min(low[v], low[u]);
}
if(tin[v] == low[v]) {
vector<int> V;
while(1) {
int U = S.back(); S.pop_back();
V.push_back(U); vis[U] = 0;
if(U == v) break;
}
if(V.size() == 1) return;
for(auto u : V) Scc[u] = 1;
}
}
int solve(int v, int t) {
if(Scc[v]) return 1;
if(station[v]) t = N;
if(t == 0) return 0;
for(auto u : adj[v]) {
if(solve(u, t - 1))
return 1;
}
return 0;
}
vector<int> who_wins(vector<int> A, vector<int> R,
vector<int> U, vector<int> V) {
N = A.size(), M = U.size();
for(int l = 0; l < N; l++)
station[l] = R[l];
for(int l = 0; l < M; l++) {
int u = U[l], v = V[l];
if(u == v) {
Scc[u] = 1; continue;
}
adj[u].pb(v);
}
memset(tin, -1, sizeof tin);
for(int l = 0; l < N; l++) {
if(tin[l] != -1) continue;
dfs(l);
}
vector<int> res(N);
for(int l = 0; l < N; l++) {
res[l] = solve(l, N);
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
1492 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 |
1 ms |
340 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 |
66 ms |
1480 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 |
7 ms |
1228 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 |
7 ms |
1364 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 |
4 ms |
1492 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |