#include "train.h"
#include<bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define P push
int n,m;
vector<int> ed[5000];
bool own[5000];
bool charge[5000];
bool self[5000];
vector<int> are,bor;
vector<int> SUB_1() {
vector<int> ans(n);
for(int i=0;i<n;i++){
for(int j=i;j<n;j++){
if(self[j] && ed[j].size()==1){
if(charge[j])ans[i]=1;
else ans[i]=0;
break;
}
if(own[j] && charge[j] && self[j]){ans[i]=1;break;}
if(!own[j] && !charge[j] && self[j]){ans[i]=0;break;}
}
}
return ans;
}
bool visited[5000];
bool ok;
void dfs(int x,int ch){
if(charge[x])ch++;
if(visited[x]){
if(ch>0)ok=true;
return;
}
visited[x]=true;
for(int i=0;i<ed[x].size();i++){
int y=ed[x][i];
dfs(y,ch);
}
if(charge[x])ch--;
return;
}
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
n=a.size();m=u.size();
memset(self,false,sizeof(self));
for(int i=0;i<m;i++){
ed[u[i]].PB(v[i]);
if(u[i]==v[i])self[u[i]]=true;
}
for(int i=0;i<n;i++){
own[i]=a[i];
charge[i]=r[i];
if(a[i])are.PB(i);
else bor.PB(i);
}
vector<int> ans(n);
for(int i=0;i<n;i++){
memset(visited,false,sizeof(visited));
ok=false;
dfs(i,0);
ans[i]=ok;
}
return ans;
return SUB_1();
}
Compilation message
train.cpp: In function 'void dfs(int, int)':
train.cpp:41:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(int i=0;i<ed[x].size();i++){
| ~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
191 ms |
1036 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
150 ms |
1316 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
797 ms |
1052 KB |
3rd lines differ - on the 696th token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1084 ms |
1176 KB |
3rd lines differ - on the 2nd token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
191 ms |
1036 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |