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 <bits/stdc++.h>
using namespace std;
#include "dungeons.h"
#define pb push_back
const int nax=4e5+5;
vector<int> adj[nax];
vector<int> ss,ll,ww,pp;
int depth[nax];
int N;
int dfs(int x){
if(x==N) return 0;
if(depth[x]!=0) return depth[x];
depth[x]=1;
depth[x]+=dfs(ss[x]);
return depth[x];
}
void init(int n, std::vector<int> s, std::vector<int> p, std::vector<int> w, std::vector<int> l) {
ss=s;
pp=p;
ww=w;
ll=l;
N=n;
for (int i = 0; i < n; ++i)
{
adj[i].pb(ww[i]);
}
for (int i = 0; i < n; ++i)
{
if(depth[i]==0) dfs(i);
}
return;
}
long long simulate(int x, int z) {
long long ans=z;
if(ans>=ss[x]) return ans+1ll*(1+depth[ww[x]])*ss[x];
else return ans+1ll*(1+depth[ll[x]])*ss[x];
}
# | 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... |