답안 #472624

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
472624 2021-09-13T22:18:10 Z Ozy Dynamic Diameter (CEOI19_diameter) C++17
24 / 100
5000 ms 27420 KB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define repa(i,a,b) for (int i = (a); i >= (b); i--)
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "

#define MAX 100000
#define dis first
#define prof second

lli n,q,w,a,b,c,last;
vector<lli> hijos[MAX+2];
map<lli,lli> mapa[MAX+2];
pair<lli,lli> arr[MAX+2];
pair<lli,lli> res;

pair<lli,lli> busca(lli pos, lli padre) {

    bool hoja=true;
    pair<lli,lli> act,ult;

    ult.dis = 0;
    for (auto h : hijos[pos]) {
        if(h == padre) continue;

        hoja = false;
        act = busca(h,pos);
        act.dis += mapa[pos][h];

        if (act.dis > ult.dis) ult = act;
    }

    if (hoja) return{0,pos};
    else return ult;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> q >> w;
    rep(i,1,n-1) {
        cin >> a >> b >> c;
        hijos[a].push_back(b);
        hijos[b].push_back(a);
        mapa[a][b] = c;
        mapa[b][a] = c;

        arr[i] = {a,b};
    }

    last = 0;
    rep(i,1,q) {

        cin >> a >> c;
        a += last;
        a %= (n-1);
        a++;
        c += last;
        c %= w;

        b = arr[a].first;
        a = arr[a].second;
        mapa[a][b] = c;
        mapa[b][a] = c;

        res = busca(1,0);
        res = busca(res.second,0);

        cout << res.dis << "\n";
        last = res.dis;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7244 KB Output is correct
2 Correct 5 ms 7368 KB Output is correct
3 Correct 5 ms 7244 KB Output is correct
4 Correct 5 ms 7344 KB Output is correct
5 Correct 5 ms 7244 KB Output is correct
6 Correct 5 ms 7244 KB Output is correct
7 Correct 5 ms 7372 KB Output is correct
8 Correct 5 ms 7372 KB Output is correct
9 Correct 5 ms 7372 KB Output is correct
10 Correct 5 ms 7372 KB Output is correct
11 Correct 4 ms 7372 KB Output is correct
12 Correct 5 ms 7372 KB Output is correct
13 Correct 5 ms 7372 KB Output is correct
14 Correct 5 ms 7372 KB Output is correct
15 Correct 5 ms 7372 KB Output is correct
16 Correct 6 ms 7372 KB Output is correct
17 Correct 5 ms 7372 KB Output is correct
18 Correct 5 ms 7360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7244 KB Output is correct
2 Correct 5 ms 7368 KB Output is correct
3 Correct 5 ms 7244 KB Output is correct
4 Correct 5 ms 7344 KB Output is correct
5 Correct 5 ms 7244 KB Output is correct
6 Correct 5 ms 7244 KB Output is correct
7 Correct 5 ms 7372 KB Output is correct
8 Correct 5 ms 7372 KB Output is correct
9 Correct 5 ms 7372 KB Output is correct
10 Correct 5 ms 7372 KB Output is correct
11 Correct 4 ms 7372 KB Output is correct
12 Correct 5 ms 7372 KB Output is correct
13 Correct 5 ms 7372 KB Output is correct
14 Correct 5 ms 7372 KB Output is correct
15 Correct 5 ms 7372 KB Output is correct
16 Correct 6 ms 7372 KB Output is correct
17 Correct 5 ms 7372 KB Output is correct
18 Correct 5 ms 7360 KB Output is correct
19 Correct 277 ms 7612 KB Output is correct
20 Correct 293 ms 7840 KB Output is correct
21 Correct 291 ms 7628 KB Output is correct
22 Correct 335 ms 7716 KB Output is correct
23 Correct 2514 ms 8480 KB Output is correct
24 Correct 2638 ms 8500 KB Output is correct
25 Correct 2732 ms 8784 KB Output is correct
26 Correct 2813 ms 9084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7496 KB Output is correct
2 Correct 5 ms 7372 KB Output is correct
3 Correct 6 ms 7376 KB Output is correct
4 Correct 24 ms 7560 KB Output is correct
5 Correct 101 ms 8492 KB Output is correct
6 Correct 5 ms 7244 KB Output is correct
7 Correct 6 ms 7372 KB Output is correct
8 Correct 13 ms 7368 KB Output is correct
9 Correct 93 ms 7480 KB Output is correct
10 Correct 860 ms 7812 KB Output is correct
11 Correct 4346 ms 9136 KB Output is correct
12 Correct 19 ms 8248 KB Output is correct
13 Correct 120 ms 8268 KB Output is correct
14 Correct 1148 ms 8340 KB Output is correct
15 Execution timed out 5100 ms 8672 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 7500 KB Output is correct
2 Correct 341 ms 7680 KB Output is correct
3 Correct 1691 ms 8404 KB Output is correct
4 Correct 3398 ms 8992 KB Output is correct
5 Correct 366 ms 9292 KB Output is correct
6 Correct 3604 ms 9436 KB Output is correct
7 Execution timed out 5053 ms 9728 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5063 ms 27420 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 7244 KB Output is correct
2 Correct 5 ms 7368 KB Output is correct
3 Correct 5 ms 7244 KB Output is correct
4 Correct 5 ms 7344 KB Output is correct
5 Correct 5 ms 7244 KB Output is correct
6 Correct 5 ms 7244 KB Output is correct
7 Correct 5 ms 7372 KB Output is correct
8 Correct 5 ms 7372 KB Output is correct
9 Correct 5 ms 7372 KB Output is correct
10 Correct 5 ms 7372 KB Output is correct
11 Correct 4 ms 7372 KB Output is correct
12 Correct 5 ms 7372 KB Output is correct
13 Correct 5 ms 7372 KB Output is correct
14 Correct 5 ms 7372 KB Output is correct
15 Correct 5 ms 7372 KB Output is correct
16 Correct 6 ms 7372 KB Output is correct
17 Correct 5 ms 7372 KB Output is correct
18 Correct 5 ms 7360 KB Output is correct
19 Correct 277 ms 7612 KB Output is correct
20 Correct 293 ms 7840 KB Output is correct
21 Correct 291 ms 7628 KB Output is correct
22 Correct 335 ms 7716 KB Output is correct
23 Correct 2514 ms 8480 KB Output is correct
24 Correct 2638 ms 8500 KB Output is correct
25 Correct 2732 ms 8784 KB Output is correct
26 Correct 2813 ms 9084 KB Output is correct
27 Correct 4 ms 7496 KB Output is correct
28 Correct 5 ms 7372 KB Output is correct
29 Correct 6 ms 7376 KB Output is correct
30 Correct 24 ms 7560 KB Output is correct
31 Correct 101 ms 8492 KB Output is correct
32 Correct 5 ms 7244 KB Output is correct
33 Correct 6 ms 7372 KB Output is correct
34 Correct 13 ms 7368 KB Output is correct
35 Correct 93 ms 7480 KB Output is correct
36 Correct 860 ms 7812 KB Output is correct
37 Correct 4346 ms 9136 KB Output is correct
38 Correct 19 ms 8248 KB Output is correct
39 Correct 120 ms 8268 KB Output is correct
40 Correct 1148 ms 8340 KB Output is correct
41 Execution timed out 5100 ms 8672 KB Time limit exceeded
42 Halted 0 ms 0 KB -