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;
#define MAXN 100010
vector<long long> adj[MAXN];
bool pos[MAXN];
long long d[MAXN],c[MAXN];
long long n,q;
long long br;
void dfs(long long node,long long vv)
{
pos[node]=true;
vv=-c[node];
if (vv<=0)
{
br=node;
return;
}
long long s=adj[node].size();
for (long long i=0;i<s;i++)
{
long long sled=adj[node][i];
if (pos[sled]==false) dfs(sled,vv);
}
}
int main()
{
cin>>n>>q;
for (long long i=1;i<=n;i++) cin>>d[i]>>c[i];
for (long long i=1;i<n;i++) adj[i].push_back(i+1);
for (long long i=1;i<=q;i++)
{
long long r,v;
cin>>r>>v;
br=0;
dfs(r,v);
cout<<br<<endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |