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 <iostream>
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define repa(i,a,b) for (int i = (a); i >= (b); i--)
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define MAX 100000
#define dis first
#define prof second
lli n,q,w,a,b,c,last;
vector<lli> hijos[MAX+2];
map<lli,lli> mapa[MAX+2];
pair<lli,lli> arr[MAX+2];
pair<lli,lli> res;
pair<lli,lli> busca(lli pos, lli padre) {
bool hoja=true;
pair<lli,lli> act,ult;
ult.dis = 0;
for (auto h : hijos[pos]) {
if(h == padre) continue;
hoja = false;
act = busca(h,pos);
act.dis += mapa[pos][h];
if (act.dis > ult.dis) ult = act;
}
if (hoja) return{0,pos};
else return ult;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> q >> w;
rep(i,1,n-1) {
cin >> a >> b >> c;
hijos[a].push_back(b);
hijos[b].push_back(a);
mapa[a][b] = c;
mapa[b][a] = c;
arr[i] = {a,b};
}
last = 0;
rep(i,1,q) {
cin >> a >> c;
a += last;
a %= (n-1);
a++;
c += last;
c %= w;
b = arr[a].first;
a = arr[a].second;
mapa[a][b] = c;
mapa[b][a] = c;
res = busca(1,0);
res = busca(res.second,0);
cout << res.dis << "\n";
last = res.dis;
}
}
# | 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... |