답안 #578797

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
578797 2022-06-18T03:53:05 Z talant117408 Dynamic Diameter (CEOI19_diameter) C++17
31 / 100
2433 ms 28128 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

#define long                unsigned long 
#define pb                  push_back
#define mp                  make_pair
#define all(v)              (v).begin(),(v).end()
#define rall(v)             (v).rbegin(),(v).rend()
#define lb                  lower_bound
#define ub                  upper_bound
#define sz(v)               int((v).size())
#define do_not_disturb      ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl                '\n'

const int N = 1e5+7;
set <pair <int, ll>> graph[N];
vector <pair <pii, ll>> edges;
ll df, vf;
int n, q;
ll w;

void find_furthest(int v, int p, ll dist = 0) {
    if (dist > df) {
        df = dist;
        vf = v;
    }
    for (auto to : graph[v]) {
        if (to.first == p) continue;
        find_furthest(to.first, v, dist+to.second);
    }
}

void subtask3() {
    for (auto to : edges) {
        if (to.first.first != 1) {
            return;
        }
    }
    set <pair <ll, int>, greater <pair <ll, int>>> st;
    for (auto to : edges) {
        st.insert(mp(to.second, to.first.second));
    }
    ll last = 0;
    while (q--) {
        ll d, e;
        cin >> d >> e;
        d = (d + last) % (n - 1);
        e = (e + last) % w;
        auto &c = edges[d].second;
        auto b = edges[d].first.second;
        st.erase(st.find(mp(c, b)));
        c = e;
        st.insert(mp(c, b));
        ll ans = 0;
        ll cnt = 0;
        for (auto to : st) {
            ans += to.first;
            if (++cnt > 1) break;
        }
        cout << ans << endl;
        last = ans;
    }
    exit(0);
}

void solve() {
    cin >> n >> q >> w;
    for (int i = 0; i < n-1; i++) {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        if (a > b) swap(a, b);
        edges.pb(mp(mp(a, b), c));
        graph[a].insert(mp(b, c));
        graph[b].insert(mp(a, c));
    }
    
    subtask3();
    
    if (n <= 5000) {
        ll last = 0;
        while (q--) {
            ll d, e;
            cin >> d >> e;
            d = (d + last) % (n - 1);
            e = (e + last) % w;
            auto a = edges[d].first.first, b = edges[d].first.second;
            auto &c = edges[d].second;
            graph[a].erase(graph[a].find(mp(b, c)));
            graph[b].erase(graph[b].find(mp(a, c)));
            c = e;
            graph[a].insert(mp(b, c));
            graph[b].insert(mp(a, c));
            df = vf = 0;
            find_furthest(1, 1);
            df = 0;
            find_furthest(vf, vf);
            cout << df << endl;
            last = df;
        }
    }
}

int main() {
    do_not_disturb
    
    int t = 1;
    //~ cin >> t;
    while (t--) {
        solve();
    }
    
    return 0;
}
/*

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 4 ms 5012 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 4 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 4 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 4 ms 5012 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 4 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 4 ms 4948 KB Output is correct
19 Correct 227 ms 5176 KB Output is correct
20 Correct 229 ms 5160 KB Output is correct
21 Correct 263 ms 5204 KB Output is correct
22 Correct 277 ms 5224 KB Output is correct
23 Correct 1742 ms 5732 KB Output is correct
24 Correct 1853 ms 5860 KB Output is correct
25 Correct 2004 ms 5916 KB Output is correct
26 Correct 2433 ms 6092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 9 ms 5076 KB Output is correct
5 Correct 36 ms 5400 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 4 ms 5076 KB Output is correct
8 Correct 3 ms 5076 KB Output is correct
9 Correct 4 ms 5076 KB Output is correct
10 Correct 15 ms 5172 KB Output is correct
11 Correct 43 ms 5572 KB Output is correct
12 Correct 6 ms 5972 KB Output is correct
13 Correct 7 ms 6056 KB Output is correct
14 Correct 8 ms 6056 KB Output is correct
15 Correct 16 ms 6372 KB Output is correct
16 Correct 54 ms 7476 KB Output is correct
17 Correct 102 ms 26540 KB Output is correct
18 Correct 94 ms 26612 KB Output is correct
19 Correct 93 ms 26552 KB Output is correct
20 Correct 111 ms 26812 KB Output is correct
21 Correct 215 ms 28128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 5076 KB Output is correct
2 Correct 243 ms 5204 KB Output is correct
3 Correct 1247 ms 5564 KB Output is correct
4 Correct 2422 ms 5728 KB Output is correct
5 Incorrect 7 ms 6352 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 97 ms 19008 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 4 ms 5012 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 4 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 4 ms 4948 KB Output is correct
19 Correct 227 ms 5176 KB Output is correct
20 Correct 229 ms 5160 KB Output is correct
21 Correct 263 ms 5204 KB Output is correct
22 Correct 277 ms 5224 KB Output is correct
23 Correct 1742 ms 5732 KB Output is correct
24 Correct 1853 ms 5860 KB Output is correct
25 Correct 2004 ms 5916 KB Output is correct
26 Correct 2433 ms 6092 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 3 ms 4948 KB Output is correct
29 Correct 3 ms 4948 KB Output is correct
30 Correct 9 ms 5076 KB Output is correct
31 Correct 36 ms 5400 KB Output is correct
32 Correct 3 ms 4948 KB Output is correct
33 Correct 4 ms 5076 KB Output is correct
34 Correct 3 ms 5076 KB Output is correct
35 Correct 4 ms 5076 KB Output is correct
36 Correct 15 ms 5172 KB Output is correct
37 Correct 43 ms 5572 KB Output is correct
38 Correct 6 ms 5972 KB Output is correct
39 Correct 7 ms 6056 KB Output is correct
40 Correct 8 ms 6056 KB Output is correct
41 Correct 16 ms 6372 KB Output is correct
42 Correct 54 ms 7476 KB Output is correct
43 Correct 102 ms 26540 KB Output is correct
44 Correct 94 ms 26612 KB Output is correct
45 Correct 93 ms 26552 KB Output is correct
46 Correct 111 ms 26812 KB Output is correct
47 Correct 215 ms 28128 KB Output is correct
48 Correct 26 ms 5076 KB Output is correct
49 Correct 243 ms 5204 KB Output is correct
50 Correct 1247 ms 5564 KB Output is correct
51 Correct 2422 ms 5728 KB Output is correct
52 Incorrect 7 ms 6352 KB Output isn't correct
53 Halted 0 ms 0 KB -