Submission #768798

# Submission time Handle Problem Language Result Execution time Memory
768798 2023-06-28T16:08:50 Z zsombor Dreaming (IOI13_dreaming) C++17
18 / 100
32 ms 13688 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include "dreaming.h"
using namespace std;

int mn = 1e9, ans = 0;
vector <vector <pair <int, int>>> g(1e5);
vector <int> par(1e5, -1);
vector <int> down1(1e5, 0);
vector <int> down2(1e5, 0);
vector <int> up(1e5, 0);
vector <int> far(1e5, 0);
vector <bool> done(1e5, false);
vector <int> MN;

void dfs1(int x) {
    for (auto p : g[x]) {
        int i = p.first, w = p.second;
        if (i == par[x]) continue;
        par[i] = x;
        dfs1(i);
        if (down1[i] + w > down1[x]) down1[x] = down1[i] + w;
        else if(down1[i] + w > down2[x]) down2[x] = down1[i] + w;
    }
}

void dfs2(int x) {
    for (auto p : g[x]) {
        int i = p.first, w = p.second;
        if (i == par[x]) continue;
        up[i] = max(up[x], (down1[x] == down1[i] + w ? down2[x] : down1[x])) + w;
        dfs2(i);
    }
}

void dfs3(int x) {
    far[x] = max(down1[x], up[x]);
    mn = min(mn, far[x]);
    ans = max(ans, far[x]);
    done[x] = true;
    for (auto p : g[x]) {
        int i = p.first;
        if (i == par[x]) continue;
        dfs3(i);
    }
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    for (int i = 0; i < M; i++) {
        g[A[i]].push_back({ B[i],T[i] });
        g[B[i]].push_back({ A[i],T[i] });
    }
    for (int i = 0; i < N; i++) if (!done[i]) {
        dfs1(i);
        dfs2(i);
        dfs3(i);
        MN.push_back(mn);
        mn = 1e9;
    }
    sort(MN.begin(), MN.end());
    reverse(MN.begin(), MN.end());
    if (MN.size() >= 2) ans = max(ans, MN[0] + MN[1] + L);
    if (MN.size() >= 3) ans = max(ans, MN[1] + MN[2] + 2 * L);
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 32 ms 13688 KB Output is correct
2 Correct 32 ms 13416 KB Output is correct
3 Correct 23 ms 12144 KB Output is correct
4 Correct 7 ms 5920 KB Output is correct
5 Correct 6 ms 5332 KB Output is correct
6 Correct 10 ms 6572 KB Output is correct
7 Incorrect 2 ms 4648 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4564 KB Output is correct
2 Correct 2 ms 4636 KB Output is correct
3 Incorrect 2 ms 4564 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 13688 KB Output is correct
2 Correct 32 ms 13416 KB Output is correct
3 Correct 23 ms 12144 KB Output is correct
4 Correct 7 ms 5920 KB Output is correct
5 Correct 6 ms 5332 KB Output is correct
6 Correct 10 ms 6572 KB Output is correct
7 Incorrect 2 ms 4648 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 7720 KB Output is correct
2 Correct 15 ms 7752 KB Output is correct
3 Correct 20 ms 7764 KB Output is correct
4 Correct 15 ms 7764 KB Output is correct
5 Correct 15 ms 7764 KB Output is correct
6 Correct 16 ms 8152 KB Output is correct
7 Correct 16 ms 7896 KB Output is correct
8 Correct 15 ms 7616 KB Output is correct
9 Correct 15 ms 7664 KB Output is correct
10 Correct 15 ms 7764 KB Output is correct
11 Correct 2 ms 4564 KB Output is correct
12 Correct 5 ms 5292 KB Output is correct
13 Correct 5 ms 5328 KB Output is correct
14 Correct 5 ms 5200 KB Output is correct
15 Correct 5 ms 5200 KB Output is correct
16 Correct 5 ms 5284 KB Output is correct
17 Correct 5 ms 5200 KB Output is correct
18 Correct 5 ms 5288 KB Output is correct
19 Correct 5 ms 5200 KB Output is correct
20 Correct 2 ms 4644 KB Output is correct
21 Correct 3 ms 4644 KB Output is correct
22 Correct 2 ms 4564 KB Output is correct
23 Correct 4 ms 5200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4564 KB Output is correct
2 Correct 2 ms 4636 KB Output is correct
3 Incorrect 2 ms 4564 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 13688 KB Output is correct
2 Correct 32 ms 13416 KB Output is correct
3 Correct 23 ms 12144 KB Output is correct
4 Correct 7 ms 5920 KB Output is correct
5 Correct 6 ms 5332 KB Output is correct
6 Correct 10 ms 6572 KB Output is correct
7 Incorrect 2 ms 4648 KB Output isn't correct
8 Halted 0 ms 0 KB -