#include "train.h"
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define ff first
#define ss second
#define ln "\n"
#define ld long double
vector<ll> are;
vector<ll> isc;
vector<pair<ll, ll>> edge;
vector<vector<ll>> A;
ll n, m;
void dfs(ll u, vector<ll> &vis, vector<ll> &dp, vector<ll> &cnt, ll top){
cnt[u]=top;
if (isc[u]) top++;
vis[u]=1;
dp[u]=0;
for (auto i:A[u]){
ll v = edge[i].ff^edge[i].ss^u;
if (vis[v]==1) {
if (cnt[v]==top) dp[u]=1;
continue;
}else if (vis[v]==0){
dfs(v, vis, dp, cnt, top);
}
dp[u]|=dp[v];
}
vis[u]=2;
}
void order(ll u, vector<ll> &vis, vector<ll> &ord){
vis[u]=1;
for (auto i:A[u]){
ll v = edge[i].ff^edge[i].ss^u;
if(!vis[v]) order(v, vis, ord);
}
ord.push_back(u);
}
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
n=a.size(); m=v.size();
isc=r; are=a;
A.clear(); A.resize(n);
edge.clear(); edge.resize(m);
for (ll i=0; i<m; i++){
edge[i] = {u[i], v[i]};
A[u[i]].push_back(i);
}
vector<ll> vis(n), dp(n), cnt(n);
vector<ll> ord;
for (ll i=0; i<n; i++){
if (!vis[i]) order(i, vis, ord);
}
vis.assign(n, 0);
reverse(ord.begin(), ord.end());
for (auto i:ord){
if (!vis[i]){
dfs(i, vis, dp, cnt, 0);
}
}
for (ll i=0; i<n; i++) dp[i]=!dp[i];
return dp;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
1624 KB |
3rd lines differ - on the 14th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 2nd token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1980 KB |
Output is correct |
2 |
Correct |
5 ms |
1960 KB |
Output is correct |
3 |
Correct |
5 ms |
1884 KB |
Output is correct |
4 |
Incorrect |
6 ms |
1884 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1628 KB |
Output is correct |
2 |
Incorrect |
5 ms |
1420 KB |
3rd lines differ - on the 458th token, expected: '0', found: '1' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
1884 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
1624 KB |
3rd lines differ - on the 14th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |