Submission #713685

# Submission time Handle Problem Language Result Execution time Memory
713685 2023-03-22T19:58:03 Z thimote75 Dreaming (IOI13_dreaming) C++14
0 / 100
45 ms 13132 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;
}

num _travelTime(int N, int M, num 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 45 ms 13132 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 45 ms 13132 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 6948 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 45 ms 13132 KB Output isn't correct
2 Halted 0 ms 0 KB -