This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
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);
for (ll i=0; i<n; i++){
if (!vis[i]){
dfs(i, vis, dp, cnt, 0);
}
}
for (ll i=0; i<n; i++) dp[i]=!dp[i];
return dp;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |