//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
#define endl '\n'
#include "train.h"
vector<int> adj[5001];
vector<int> adj2[5001];
vector<int> adj3[5001];
int cyc[5001];
int vis[5001];
int ok=0;
int cur=-1;
void dfs(int no){
vis[no]=1;
for(auto j:adj2[no]){
if(vis[j]==0){
dfs(j);
}
else if(vis[j]==1){
if(j==cur){
ok=1;
}
}
}
}
void dfs2(int no){
vis[no]=1;
for(auto j:adj[no]){
if(vis[j]==0){
dfs2(j);
}
}
}
vector<int> who_wins(vector<int> aa, vector<int> bb,vector<int> uu,vector<int> vv) {
int n=aa.size();
int m=uu.size();
for(int i=0;i<m;i++){
adj[uu[i]].pb(vv[i]);
//if(bb[uu[i]]==0 and bb[vv[i]]==0){
adj2[uu[i]].pb(vv[i]);
//}
}
for(int i=0;i<n;i++){
if(bb[i]==0){
cur=i;
for(int j=0;j<n;j++){
vis[j]=0;
}
ok=0;
dfs(i);
cyc[i]=ok;
}
//else{
// cyc[i]=0;
//}
}
vector<int> ans;
for(int i=0;i<n;i++){
ans.pb(0);
for(int j=0;j<n;j++){
vis[j]=0;
}
dfs2(i);
for(int j=0;j<n;j++){
if(vis[j]==1 and cyc[j]==1 and bb[j]==1){
ans[i]=1;
}
}
/*for(int j=i;j<n;j++){
int st=0;
int st2=0;
for(auto ii:adj[j]){
if(ii==j){
st=1;
}
if(ii==j+1){
st2=1;
}
}
if(st==1){
if(st2==0){
if(bb[j]==1){
ans[i]=1;
}
else{
}
break;
}
if(aa[j]==0){
if(bb[j]==0){
break;
}
}
if(aa[j]==1 and bb[j]==1){
ans[i]=1;
break;
}
}
}*/
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
401 ms |
1452 KB |
3rd lines differ - on the 14th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
588 KB |
3rd lines differ - on the 2nd token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
413 ms |
1728 KB |
Output is correct |
2 |
Correct |
416 ms |
1824 KB |
Output is correct |
3 |
Correct |
403 ms |
1760 KB |
Output is correct |
4 |
Incorrect |
1924 ms |
1720 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
941 ms |
1448 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2079 ms |
1548 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
401 ms |
1452 KB |
3rd lines differ - on the 14th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |