Submission #768481

# Submission time Handle Problem Language Result Execution time Memory
768481 2023-06-28T07:54:29 Z boris_mihov Dreaming (IOI13_dreaming) C++17
18 / 100
1000 ms 11572 KB
#include "dreaming.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>

typedef long long llong;
const int MAXN = 100000 + 10;
const int INF  = 1e9;

int n, m;
int dp[MAXN];
int dp2[MAXN];
int next[MAXN];
bool vis[MAXN];
std::vector <std::pair <int,int>> g[MAXN];
std::vector <int> dists;

void dfsDown(int node, int p)
{
    dp[node] = dp2[node] = 0;
    for (const auto &[u, d] : g[node])
    {
        if (u == p)
        {
            continue;
        }

        dfsDown(u, node);
        if (dp[u] + d > dp[node])
        {
            dp2[node] = dp[node];
            dp[node] = dp[u] + d;
            next[node] = u; 
        } else if (dp[u] + d > dp2[node])
        {
            dp2[node] = dp[u] + d; 
        }
    }
}

int dfsUp(int node, int p, int edge)
{
    vis[node] = true;
    if (p != 0)
    {
        if (next[p] != node)
        {
            if (dp[p] + edge > dp[node])
            {
                dp2[node] = dp[node];
                dp[node] = dp[p] + edge;
                next[node] = p;
            } else if (dp[p] + edge > dp2[node])
            {
                dp2[node] = dp[p] + edge;
            }
        } else
        { 
            if (dp2[p] + edge > dp[node])
            {
                dp2[node] = dp[node];
                dp[node] = dp2[p] + edge;
                next[node] = p;
            } else if (dp2[p] + edge > dp2[node])
            {
                dp2[node] = dp2[p] + edge;
            }
        }
    }

    int res = dp[node];
    dfsDown(node, 0);
    int ans = dp[node];
    assert(res == dp[node]);
    for (const auto &[u, d] : g[node])
    {
        if (u != p)
        {
            ans = std::min(ans, dfsUp(u, node, d));
        }
    }

    return ans;
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) 
{
    n = N;
    m = M;
    for (int i = 0 ; i < m ; ++i)
    {
        g[A[i] + 1].push_back({B[i] + 1, T[i]});
        g[B[i] + 1].push_back({A[i] + 1, T[i]});
    }

    for (int i = 1 ; i <= n ; ++i)
    {
        if (vis[i])
        {
            continue;
        }

        dfsDown(i, 0);
        dists.push_back(dfsUp(i, 0, 0));
    }

    std::sort(dists.begin(), dists.end());
    if (dists.size() == 1) return dists[0];
    int ans = dists[dists.size() - 2] + dists[dists.size() - 1] + L;
    if (dists.size() >= 3) ans = std::max(ans, dists[dists.size() - 3] + dists[dists.size() - 2] + 2*L);
    return ans;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1087 ms 11572 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 5204 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1087 ms 11572 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 22 ms 6532 KB Output is correct
2 Correct 15 ms 6520 KB Output is correct
3 Correct 18 ms 6488 KB Output is correct
4 Correct 15 ms 6576 KB Output is correct
5 Correct 16 ms 6548 KB Output is correct
6 Correct 16 ms 7036 KB Output is correct
7 Correct 24 ms 6732 KB Output is correct
8 Correct 18 ms 6512 KB Output is correct
9 Correct 18 ms 6484 KB Output is correct
10 Correct 21 ms 6632 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 6 ms 4560 KB Output is correct
13 Correct 4 ms 4560 KB Output is correct
14 Correct 5 ms 4560 KB Output is correct
15 Correct 4 ms 4496 KB Output is correct
16 Correct 4 ms 4564 KB Output is correct
17 Correct 4 ms 4188 KB Output is correct
18 Correct 4 ms 4568 KB Output is correct
19 Correct 4 ms 4572 KB Output is correct
20 Correct 2 ms 2656 KB Output is correct
21 Correct 2 ms 2656 KB Output is correct
22 Correct 2 ms 2656 KB Output is correct
23 Correct 6 ms 4572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 5204 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1087 ms 11572 KB Time limit exceeded
2 Halted 0 ms 0 KB -