#include <bits/stdc++.h>
#include "train.h"
using namespace std;
const int N = 5001 ;
vector<int> adj[N] ;
void dfs(int i , vector<int>&vis,bool flg , vector<int>& r ){
vis[i]=1 ;
for(int x: adj[i]){
if(flg){
if(vis[x]==0&&r[x]==0){
dfs(x,vis,flg,r);
}
continue ;
}
if(vis[x]==0) dfs(x,vis,flg,r) ;
}
return ;
}
vector<int> who_wins0(vector<int> a,vector<int> r,vector<int> u,vector<int>v){
int n = a.size() ;
for(int i=0;i<u.size();i++)adj[u[i]].push_back(v[i]) ;
vector<vector<int>> reachable(n) ;
for(int i=0;i<n;i++){
reachable[i].resize(n) ;
dfs(i,reachable[i],0,r);
reachable[i][i]=0 ;
for(int x : adj[i]) if(x==i) reachable[i][i]=1;
}
vector<int> cycle(n) ;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(reachable[i][j]&&reachable[j][i]){
cycle[i]=1;
}
}
}
////////////
vector<vector<int>> reachablee(n) ;
for(int i=0;i<n;i++){
reachablee[i].resize(n);
if(r[i]) continue ;
dfs(i,reachablee[i],1,r) ;
reachablee[i][i]=0;
for(int x: adj[i]) if(x==i) reachablee[i][i]=1 ;
}
////////////
vector<int> cyclee(n) ;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(reachablee[i][j]&&reachablee[j][i]){
cyclee[j]=1;
}
}
}
////////////
vector<int> ans(n,1) ;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(adj[j].empty()&&(reachable[i][j]||i==j)){
ans[i]=0;
break;
}
if(cyclee[j]&&(reachable[i][j]||i==j)){
ans[i]=0 ;
break ;
}
}
}
return ans ;
}
vector<int> who_wins1(vector<int> a,vector<int> r,vector<int> u,vector<int>v){
int n = a.size() ;
for(int i=0;i<u.size();i++)adj[u[i]].push_back(v[i]) ;
vector<vector<int>> reachable(n) ;
for(int i=0;i<n;i++){
reachable[i].resize(n) ;
dfs(i,reachable[i],0,r);
reachable[i][i]=0 ;
for(int x : adj[i]) if(x==i) reachable[i][i]=1;
}
vector<int> cycle(n) ;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(reachable[i][j]&&reachable[j][i]){
cycle[i]=1;
}
}
}
vector<int> ans(n) ;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(cycle[j]&&(reachable[i][j]||i==j)&&r[j]){
ans[i]=1 ;
break ;
}
}
}
return ans ;
}
vector<int> who_wins(vector<int> a,vector<int> r,vector<int> u,vector<int>v){
if(a[0]==0) return who_wins0(a,r,u,v);
return who_wins1(a,r,u,v);
}
Compilation message
train.cpp: In function 'std::vector<int> who_wins0(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:21:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for(int i=0;i<u.size();i++)adj[u[i]].push_back(v[i]) ;
| ~^~~~~~~~~
train.cpp: In function 'std::vector<int> who_wins1(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:78:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for(int i=0;i<u.size();i++)adj[u[i]].push_back(v[i]) ;
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
539 ms |
197220 KB |
3rd lines differ - on the 14th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
3rd lines differ - on the 8th token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
460 ms |
99504 KB |
Output is correct |
2 |
Correct |
571 ms |
99476 KB |
Output is correct |
3 |
Correct |
531 ms |
99448 KB |
Output is correct |
4 |
Correct |
1299 ms |
99404 KB |
Output is correct |
5 |
Correct |
1038 ms |
99528 KB |
Output is correct |
6 |
Correct |
905 ms |
99504 KB |
Output is correct |
7 |
Correct |
711 ms |
99432 KB |
Output is correct |
8 |
Correct |
664 ms |
99484 KB |
Output is correct |
9 |
Correct |
646 ms |
99464 KB |
Output is correct |
10 |
Correct |
618 ms |
99344 KB |
Output is correct |
11 |
Correct |
609 ms |
99520 KB |
Output is correct |
12 |
Correct |
182 ms |
99364 KB |
Output is correct |
13 |
Correct |
1373 ms |
99608 KB |
Output is correct |
14 |
Correct |
1375 ms |
99616 KB |
Output is correct |
15 |
Correct |
1396 ms |
99616 KB |
Output is correct |
16 |
Correct |
1379 ms |
99608 KB |
Output is correct |
17 |
Correct |
1397 ms |
99620 KB |
Output is correct |
18 |
Correct |
762 ms |
99248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1232 ms |
197236 KB |
Output is correct |
2 |
Correct |
636 ms |
197196 KB |
Output is correct |
3 |
Correct |
879 ms |
197248 KB |
Output is correct |
4 |
Correct |
845 ms |
197292 KB |
Output is correct |
5 |
Correct |
1219 ms |
197324 KB |
Output is correct |
6 |
Correct |
1073 ms |
197276 KB |
Output is correct |
7 |
Correct |
1102 ms |
197476 KB |
Output is correct |
8 |
Correct |
841 ms |
197252 KB |
Output is correct |
9 |
Correct |
252 ms |
197252 KB |
Output is correct |
10 |
Correct |
1519 ms |
197400 KB |
Output is correct |
11 |
Correct |
1495 ms |
197488 KB |
Output is correct |
12 |
Correct |
1483 ms |
197448 KB |
Output is correct |
13 |
Correct |
1597 ms |
197396 KB |
Output is correct |
14 |
Correct |
1025 ms |
197300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2093 ms |
151916 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
539 ms |
197220 KB |
3rd lines differ - on the 14th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |