답안 #768484

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
768484 2023-06-28T07:58:27 Z boris_mihov 꿈 (IOI13_dreaming) C++17
18 / 100
1000 ms 11596 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;
        }

        assert(dp[i] == 0);
        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;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1089 ms 11596 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1089 ms 11596 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 6508 KB Output is correct
2 Correct 15 ms 6484 KB Output is correct
3 Correct 15 ms 6504 KB Output is correct
4 Correct 16 ms 6576 KB Output is correct
5 Correct 14 ms 6524 KB Output is correct
6 Correct 15 ms 7000 KB Output is correct
7 Correct 16 ms 6748 KB Output is correct
8 Correct 14 ms 6488 KB Output is correct
9 Correct 14 ms 6396 KB Output is correct
10 Correct 15 ms 6612 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 4 ms 4560 KB Output is correct
13 Correct 4 ms 4560 KB Output is correct
14 Correct 4 ms 4560 KB Output is correct
15 Correct 4 ms 4560 KB Output is correct
16 Correct 4 ms 4572 KB Output is correct
17 Correct 4 ms 4176 KB Output is correct
18 Correct 4 ms 4560 KB Output is correct
19 Correct 4 ms 4560 KB Output is correct
20 Correct 1 ms 2644 KB Output is correct
21 Correct 1 ms 2644 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 4 ms 4560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1089 ms 11596 KB Time limit exceeded
2 Halted 0 ms 0 KB -