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"
#ifdef NYAOWO
#include "grader.cpp"
#endif
#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define eb emplace_back
#define int LL
using namespace std;
using i32 = int32_t;
using LL = long long;
using pii = pair<int, int>;
namespace {
const int MAXN = 400'000;
int n;
int vw[MAXN + 10];
int vl[MAXN + 10];
int nxtw[MAXN + 10];
int nxtl[MAXN + 10];
void _init(i32 N, vector<i32> s, vector<i32> p, vector<i32> w, vector<i32> l) {
	n = N;
	For(i, 0, n - 1) {
		vw[i] = s[i];
		vl[i] = p[i];
		nxtw[i] = w[i];
		nxtl[i] = l[i];
	}
}
int query(int pos, int val) {
	while(pos != n) {
		if(val >= vw[pos]) {
			val += vw[pos];
			pos = nxtw[pos];
		} else {
			val += vl[pos];
			pos = nxtl[pos];
		}
	}
	return val;
}
}  // namespace
void init(i32 N, std::vector<i32> s, std::vector<i32> p, std::vector<i32> w, std::vector<i32> l) {
	::_init(N, s, p, w, l);
}
long long simulate(i32 pos, i32 val) {
	return ::query(pos, val);
}
/*
3 2
2 6 9
3 1 2
2 2 3
1 0 1
0 1
2 3
24
25
*/
| # | 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... |