이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// 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... |