Submission #575135

# Submission time Handle Problem Language Result Execution time Memory
575135 2022-06-09T17:55:49 Z d4xn Dreaming (IOI13_dreaming) C++17
0 / 100
48 ms 13892 KB
#pragma GCC optimize ("Ofast")
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5+5, inf = INT_MAX;

int n, mxDis, furthest, mn;
vector<int> dp, distances;
vector<pair<int, int>> adj[N];
bitset<N> vis;

void getFurthest(int u, int par, int d) {
    vis[u] = 1;
    if (d > mxDis) {
        mxDis = d;
        furthest = u;
    }
    for (auto &[v, w] : adj[u]) {
        if (v == par) continue;
        getFurthest(v, u, d+w);
    }
}

void dfs(int u, int par, int d, bool b) {
    vis[u] = 1;
    dp[u] = max(dp[u], d);

    if (b && dp[u] < mn) mn = dp[u];

    for (auto &[v, w] : adj[u]) {
        if (v == par) continue;
        dfs(v, u, d+w, b);
    }
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    n = N;
    dp.resize(n, 0);
    for (int i = 0; i < M; i++) {
        adj[A[i]].push_back(make_pair(B[i], T[i]));
        adj[B[i]].push_back(make_pair(A[i], T[i]));
    }

    for (int i = 0; i < n; i++) {
        if (vis[i]) continue;
        mxDis = -1;
        getFurthest(i, -1, 0);
        int a = furthest;

        mxDis = -1;
        getFurthest(a, -1, 0);
        int b = furthest;

        mn = inf;
        dfs(a, -1, 0, 0);
        dfs(b, -1, 0, 1);
        distances.push_back(mn);
    }
    sort(distances.rbegin(), distances.rend());

    return max(2*L + distances[1] + distances[2], L + distances[0] + distances[1]);
}
# Verdict Execution time Memory Grader output
1 Incorrect 48 ms 13892 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 48 ms 13892 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 22 ms 6104 KB Output is correct
2 Correct 23 ms 6088 KB Output is correct
3 Correct 21 ms 6136 KB Output is correct
4 Correct 25 ms 6108 KB Output is correct
5 Correct 22 ms 6140 KB Output is correct
6 Correct 24 ms 6620 KB Output is correct
7 Correct 28 ms 6224 KB Output is correct
8 Correct 26 ms 6104 KB Output is correct
9 Correct 17 ms 6084 KB Output is correct
10 Correct 19 ms 6248 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 4 ms 3664 KB Output is correct
13 Correct 5 ms 3664 KB Output is correct
14 Correct 6 ms 3664 KB Output is correct
15 Correct 4 ms 3664 KB Output is correct
16 Correct 4 ms 3664 KB Output is correct
17 Correct 5 ms 3664 KB Output is correct
18 Correct 5 ms 3664 KB Output is correct
19 Correct 6 ms 3664 KB Output is correct
20 Incorrect 2 ms 2644 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 48 ms 13892 KB Output isn't correct
2 Halted 0 ms 0 KB -