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 int long long
#define pii pair<int, int>
int N, Q, W;
const int MAX_N = 1e5;
vector<unordered_map<int, int>> adj;
pii get_furthest(int u, int a){
pii res ={0, u};
for(auto e: adj[u]){
if(e.first!=a){
pii de = get_furthest(e.first, u);
de.first += e.second;
if(de.first>res.first){
res = de;
}
}
}
return res;
}
signed main(){
cin>>N>>Q>>W;
adj.resize(N);
vector<pii> edges;
for(int i = 0; i<N-1; i++){
int a, b, c;
cin>>a>>b>>c;
a--;b--;
adj[a][b] = c;
adj[b][a] = c;
edges.push_back({a, b});
}
int last= 0;
for(int i = 0; i<Q; i++){
int d, e;
cin>>d>>e;
d = (d+last)%(N-1);
e = (e +last)%W;
int a = edges[d].first;
int b= edges[d].second;
adj[a][b] = e;
adj[b][a] =e;
int u = get_furthest(0, -1).second;
last = get_furthest(u, -1).first;
cout<<last<<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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |