#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];
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], tin[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) {
vector<bool> seen(N, 0);
queue<int> q; q.push(v);
while(!q.empty()) {
int A = q.front(); q.pop(); seen[A] = 1;
if(Scc[A]) return 1;
for(auto u : adj[A]) {
if(seen[u]) continue;
q.push(u);
}
}
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 < 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);
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
1492 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
468 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
395 ms |
1724 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
10 ms |
1392 KB |
3rd lines differ - on the 696th token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
1596 KB |
3rd lines differ - on the 2nd token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
1492 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |