This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "train.h"
using namespace std;
vector<vector<int>> paths(1e4,vector<int> ());
vector<int> chargers(1e4);
vector<int> cost(1e4,1e9);
int loop = 0;
int n;
void dfs(int pos,int start,int coins,int charging,vector<int> visited,int time){
if(cost[pos] <= coins){
cost[pos] = min(cost[pos],time);
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 (stderr)
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:43:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for (int i = 0; i < u.size(); i++){
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |