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 <bits/stdc++.h>
#include "train.h"
//#include "grader.cpp"
using namespace std ;
const int MAX = 16 ;
int A[MAX] , R[MAX] ;
vector< vector<int> >adj(MAX) ;
int n ;
int vis[MAX] , mark[MAX] ;
int dp[16][(1 << MAX)][2] ;
bool dfs(int node , int mask , bool flag)
{
int &ret = dp[node][mask][flag] ;
if(ret != -1)
return ret ;
ret = 0 ;
for(auto &child : adj[node])
{
if((mask & (1 << child)))
{
if(flag == A[node])
ret = 1 ;
continue ;
}
bool t = dfs(child , mask | (1 << child) , flag | R[child]) ;
if(A[node] && A[child] == t)
ret = 1 ;
else if(!A[node] && A[child] != t)
ret = 1 ;
}
return ret ;
}
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v)
{
memset(dp , -1 , sizeof(dp)) ;
n = a.size() ;
int m = u.size() ;
n = a.size() ;
m = u.size() ;
for(int i = 0 ; i < n ; ++i)
A[i] = a[i] , R[i] = r[i] ;
for(int i = 0 ; i < m ; ++i)
adj[u[i]].push_back(v[i]) ;
vector<int>ans ;
for(int i = 0 ; i < n ; ++i)
{
bool t = dfs(i , 1 << i , r[i]) ;
if(A[i] == t)
ans.push_back(1) ;
else
ans.push_back(0) ;
}
return ans ;
}
# | 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... |