제출 #689742

#제출 시각아이디문제언어결과실행 시간메모리
689742overwatch9Dynamic Diameter (CEOI19_diameter)C++17
7 / 100
426 ms12064 KiB
// 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...