#include "train.h"
using namespace std;
vector<vector<int>> paths(1e4,vector<int> ());
vector<int> chargers(1e4);
vector<int> cost(1e4,-1);
int loop = 0;
int n;
void dfs(int pos,int start,int coins,int charging,vector<int> visited,int time){
if(cost[pos] <= coins)loop=1;
if(visited[pos]){
if(chargers[pos] == 1){
cost[pos] = min(cost[pos],time);
loop = 1;
}
return;
}
if(loop==1)return;
if(chargers[pos] == 1){
if(time == -1){
time = n-coins;
}
charging = 1;
coins = n;
}
if(pos==start and charging==1){cost[pos] = min(cost[pos],time);loop = 1;}
coins--;
visited[pos]=1;
if(coins <= 0)return;
for(int a:paths[pos]){
dfs(a,start,coins,charging,visited,time);
}
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
n=a.size();
chargers = r;
for (int i = 0; i < u.size(); i++){
paths[u[i]].push_back(v[i]);
}
vector<int> ans(n,0);
for (int i = 0; i < n; i++){
loop = 0;
dfs(i,i,n,chargers[i],vector<int>(n,0),-1);
ans[i] = loop;
}
return ans;
}
Compilation message
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:40:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for (int i = 0; i < u.size(); i++){
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
980 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
596 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
1236 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
1020 KB |
3rd lines differ - on the 696th token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
1236 KB |
3rd lines differ - on the 2nd token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
980 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |