#include "train.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn=5000+10;
vector<int>adj[maxn];
int n,shar[maxn],arez[maxn],m,dp[maxn],vas[maxn],dide[maxn];
int dfs(int u){
if(shar[u]||arez[u]){
return 0;
}
if(dide[u]==2){
return 0;
}
if(dide[u]==1){
return 1;
}
dide[u]=1;
int ret=0;
for(auto x:adj[u]){
ret|=dfs(x);
}
dide[u]=2;
return ret;
}
bool ber(int u){
for(int i=0;i<n;i++){
vas[i]=dide[i]=0;
}
return 1^dfs(u);
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
n=(int)a.size();
m=(int)u.size();
for(int i=0;i<=n;i++){
adj[i].clear();
shar[i]=vas[i]=dide[i]=dp[i]=arez[i]=0;
}
for(int i=0;i<n;i++){
if(a[i]){
arez[i]=1;
}
if(r[i]){
shar[i]=1;
}
}
for(int i=0;i<m;i++){
adj[u[i]].push_back(v[i]);
}
for(int i=0;i<n;i++){
dp[i]=shar[i];
}
for(int asd=0;asd<=n;asd++){
for(int i=0;i<n;i++){
if(dp[i]){
continue;
}
int cnt=0;
int f=0;
for(auto x:adj[i]){
if(dp[x]==1){
cnt++;
}
}
if(arez[i]){
if(cnt>0){
dp[i]=1;
}
}else{
if(f){
if(shar[i]==0||cnt!=(int)adj[i].size()-1){
dp[i]=0;
}
}else{
if(cnt!=(int)adj[i].size()){
dp[i]=0;
}
}
}
}
}
for(int asd=0;asd<=n;asd++){
for(int i=0;i<n;i++){
if(dp[i]){
continue;
}
int cnt=0;
int f=0;
for(auto x:adj[i]){
if(x==i&&shar[x]==1){
cnt=1;
continue;
}else if(x==i){
continue;
}
if(dp[x]==1){
cnt++;
}
}
if(arez[i]){
if(cnt>0){
dp[i]=1;
}
}else{
if(f){
if(shar[i]==0||cnt!=(int)adj[i].size()-1){
dp[i]=0;
}
}else{
if(cnt!=(int)adj[i].size()){
dp[i]=0;
}
}
}
}
}
vector<int>res(n);
for(int i=0;i<n;i++){
res[i]=dp[i];
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
70 ms |
968 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
50 ms |
1112 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
41 ms |
1116 KB |
3rd lines differ - on the 21st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
370 ms |
1112 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
70 ms |
968 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |