Submission #713687

# Submission time Handle Problem Language Result Execution time Memory
713687 2023-03-22T19:58:36 Z thimote75 Dreaming (IOI13_dreaming) C++14
18 / 100
42 ms 13256 KB
#include <bits/stdc++.h>
#include "dreaming.h"

using namespace std;

#define num long long
#define next first
#define cost second
#define t_road pair<int, num>
#define t_roads vector<t_road>
#define graph vector<t_roads>
#define ndata vector<num>

graph roads;

// here, max is refered as the first maximal
// mix is refered as the second maximal
ndata max_dist;

ndata visit_id; num stage = 0;

num computeDistance (int node, int parent, num cst) {
    max_dist[node] = cst;
    visit_id[node] = stage;

    for (t_road road : roads[node]) {
        if (road.next == parent) continue ;

        max_dist[node] = max(
            max_dist[node], 
            computeDistance(road.next, node, cst + road.cost)
        );
    }

    max_dist[node] -= cst;

    return max_dist[node] + cst;
}

num excentricity (int node, int parent, num incoming) {
    num local = max(incoming, max_dist[node]);
    visit_id[node] = stage;

    num max = 0;
    num mix = 0;
    for (t_road road : roads[node]) {
        if (road.next == parent) continue ;

        num next_d = road.cost + max_dist[road.next];
        if (next_d > max) {
            mix = max;
            max = next_d;
        } else if (next_d > mix) mix = next_d;
    }

    for (t_road road : roads[node]) {
        if (road.next == parent) continue ;

        num next_i = max == max_dist[road.next] + road.cost ? mix : max;
        if (next_i < incoming) next_i = incoming;
        local = min(local, excentricity(road.next, node, road.cost + next_i));
    }
    
    return local;
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    roads.resize(N);
    visit_id.resize(N, -1);
    max_dist.resize(N);
    for (int i = 0; i < M; i ++) {
        roads[A[i]].push_back({ B[i], T[i] });
        roads[B[i]].push_back({ A[i], T[i] });
        assert(T[i] >= 0);
    }

    for (int i = 0; i < N; i ++)
        if (visit_id[i] != stage)
            computeDistance(i, -1, 0);
    stage ++;

    vector<num> values;
    for (int i = 0; i < N; i ++)
        if (visit_id[i] != stage)
            values.push_back(excentricity(i, -1, 0));
    
    sort(values.rbegin(), values.rend());
    
    if (values.size() == 1) return values[0];
    if (values.size() == 2) return L + values[0] + values[1];

    return L + values[1] + max(values[0], values[2] + L);
}

/*
int travelTime (int N, int M, int L, int A[], int B[], int T[]) {
    cout << _travelTime(N, M, L, A, B, T) << endl;
    exit(0);
}
*/
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 13256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 13256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 6872 KB Output is correct
2 Correct 35 ms 6860 KB Output is correct
3 Correct 22 ms 6952 KB Output is correct
4 Correct 28 ms 6968 KB Output is correct
5 Correct 23 ms 6900 KB Output is correct
6 Correct 26 ms 7764 KB Output is correct
7 Correct 25 ms 7240 KB Output is correct
8 Correct 25 ms 6844 KB Output is correct
9 Correct 29 ms 6692 KB Output is correct
10 Correct 33 ms 7116 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 6 ms 5324 KB Output is correct
13 Correct 6 ms 5324 KB Output is correct
14 Correct 5 ms 5304 KB Output is correct
15 Correct 5 ms 5340 KB Output is correct
16 Correct 6 ms 5388 KB Output is correct
17 Correct 6 ms 5324 KB Output is correct
18 Correct 9 ms 5356 KB Output is correct
19 Correct 5 ms 5324 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 468 KB Output is correct
23 Correct 6 ms 5324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 13256 KB Output isn't correct
2 Halted 0 ms 0 KB -