#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){
if(visited[pos]){
if(chargers[pos] == 1){
loop = 1;
}
return;
}
if(loop==1)return;
if(chargers[pos] == 1){
charging = 1;
coins = n;
}
if(pos==start and charging==1){loop = 1;}
coins--;
visited[pos]=1;
if(coins <= 0)return;
for(int a:paths[pos]){
dfs(a,start,coins,charging,visited);
}
}
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,-1);
for (int i = 0; i < u.size(); i++){
loop = 0;
dfs(i,i,n,chargers[i],vector<int>(n,0));
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:35:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for (int i = 0; i < u.size(); i++){
| ~~^~~~~~~~~~
train.cpp:42:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for (int i = 0; i < u.size(); i++){
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
134 ms |
2852 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
852 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2081 ms |
58520 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
152 ms |
3152 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2072 ms |
46312 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
134 ms |
2852 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |