This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// subtask3
#include <iostream>
#include <set>
using namespace std;
using ll = long long;
const int MAX_N = 1e5;
struct edge {
int a, b;
ll w;
};
edge edges[MAX_N];
int main() {
int N, Q;
ll W;
cin >> N >> Q >> W;
multiset <ll> weights;
for (int i = 0; i < N-1; i++) {
int a, b;
ll w;
cin >> a >> b >> w;
edge tp;
tp.a = a;
tp.b = b;
tp.w = w;
edges[i] = tp;
weights.insert(w);
}
ll last = 0;
while (Q--) {
ll d, e;
cin >> d >> e;
d = (d + last) % (N-1);
e = (e + last) % (W);
ll old_weight = edges[d].w;
weights.erase(weights.find(old_weight));
weights.insert(e);
edges[d].w = e;
last = *weights.rbegin();
if (weights.size() >= 2)
last += *(--(--weights.end()));
cout << last << '\n';
}
}
# | 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... |