Submission #768467

# Submission time Handle Problem Language Result Execution time Memory
768467 2023-06-28T07:45:02 Z boris_mihov Dreaming (IOI13_dreaming) C++17
0 / 100
1000 ms 11660 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;
    //         }
    //     }
    // }

    dfsDown(node, 0);
    int ans = 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];
    return dists[dists.size() - 2] + dists[dists.size() - 1] + L;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1082 ms 11660 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1082 ms 11660 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 6528 KB Output is correct
2 Incorrect 14 ms 6484 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1082 ms 11660 KB Time limit exceeded
2 Halted 0 ms 0 KB -