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 "dungeons.h"
#include <bits/stdc++.h>
using namespace std;
int nnn;
vector<int>sss,ppp,www,lll;
vector<long long>winning_path(400001,INT_MAX);
vector<int>adj[400001];
void gen(void);
void init(int nn, vector<int> ss, vector<int> pp, vector<int> ww, vector<int> ll) {
nnn=nn;
sss=ss,ppp=pp,www=ww,lll=ll;
for(int i = 0 ; i < nnn ; i++) {
adj[www[i]].push_back(i);
}
gen();
}
void gen(void) {
//vector<bool>vis(nnn+1,false);
//winning_path.resize(nnn+1);
winning_path[nnn]=0;
queue<pair<int,long long>>q;
q.push({nnn,0});
long long cnt=0;
while(!q.empty()) {
pair<int,long long> u =q.front();
q.pop();
for(auto x:adj[u.first]){
if(winning_path[x]>u.second+1){
winning_path[x]=u.second+1;
q.push({x,u.second+1});
}}}}
long long simulate(int x, int zz) {
long long z=zz;
while(true) {
if(x==nnn) return z;
if(z >= sss[x] && winning_path[x]!=INT_MAX) {
long long mul = sss[x]*winning_path[x];
return z+mul;
}
z+=ppp[x];
x=lll[x];
}
}
Compilation message (stderr)
dungeons.cpp: In function 'void gen()':
dungeons.cpp:25:15: warning: unused variable 'cnt' [-Wunused-variable]
25 | long long cnt=0;
| ^~~
# | 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... |