Submission #778741

# Submission time Handle Problem Language Result Execution time Memory
778741 2023-07-10T15:58:22 Z zsombor Dreaming (IOI13_dreaming) C++17
18 / 100
38 ms 13260 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> 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) {
    done[x] = true;
    for (auto p : g[x]) {
        int i = p.first, w = p.second;
        if (done[i]) continue;
        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;
    }
    done[x] = false;
}

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

void dfs3(int x) {
    done[x] = true;
    far[x] = max(down1[x], up[x]);
    mn = min(mn, far[x]);
    ans = max(ans, far[x]);
    for (auto p : g[x]) {
        int i = p.first;
        if (done[i]) 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]) continue;
        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 34 ms 13260 KB Output is correct
2 Correct 38 ms 12960 KB Output is correct
3 Correct 24 ms 11748 KB Output is correct
4 Correct 7 ms 5548 KB Output is correct
5 Correct 6 ms 4948 KB Output is correct
6 Correct 10 ms 6280 KB Output is correct
7 Incorrect 2 ms 4248 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4180 KB Output is correct
2 Correct 2 ms 4252 KB Output is correct
3 Incorrect 2 ms 4180 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 34 ms 13260 KB Output is correct
2 Correct 38 ms 12960 KB Output is correct
3 Correct 24 ms 11748 KB Output is correct
4 Correct 7 ms 5548 KB Output is correct
5 Correct 6 ms 4948 KB Output is correct
6 Correct 10 ms 6280 KB Output is correct
7 Incorrect 2 ms 4248 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 7272 KB Output is correct
2 Correct 16 ms 7308 KB Output is correct
3 Correct 22 ms 7336 KB Output is correct
4 Correct 16 ms 7272 KB Output is correct
5 Correct 25 ms 7316 KB Output is correct
6 Correct 17 ms 7768 KB Output is correct
7 Correct 23 ms 7404 KB Output is correct
8 Correct 16 ms 7256 KB Output is correct
9 Correct 22 ms 7256 KB Output is correct
10 Correct 16 ms 7404 KB Output is correct
11 Correct 2 ms 4180 KB Output is correct
12 Correct 4 ms 4816 KB Output is correct
13 Correct 5 ms 4896 KB Output is correct
14 Correct 5 ms 4816 KB Output is correct
15 Correct 5 ms 4816 KB Output is correct
16 Correct 5 ms 4884 KB Output is correct
17 Correct 5 ms 4816 KB Output is correct
18 Correct 5 ms 4944 KB Output is correct
19 Correct 7 ms 4816 KB Output is correct
20 Correct 2 ms 4180 KB Output is correct
21 Correct 2 ms 4180 KB Output is correct
22 Correct 2 ms 4180 KB Output is correct
23 Correct 5 ms 4816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4180 KB Output is correct
2 Correct 2 ms 4252 KB Output is correct
3 Incorrect 2 ms 4180 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 34 ms 13260 KB Output is correct
2 Correct 38 ms 12960 KB Output is correct
3 Correct 24 ms 11748 KB Output is correct
4 Correct 7 ms 5548 KB Output is correct
5 Correct 6 ms 4948 KB Output is correct
6 Correct 10 ms 6280 KB Output is correct
7 Incorrect 2 ms 4248 KB Output isn't correct
8 Halted 0 ms 0 KB -