답안 #802178

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
802178 2023-08-02T10:43:09 Z borisAngelov 꿈 (IOI13_dreaming) C++17
47 / 100
55 ms 15492 KB
#include "dreaming.h"
#include <bits/stdc++.h>

using namespace std;

const int maxn = 100005;

int n, m;

vector<pair<int, int>> g[maxn];

long long dp[maxn];
bool visited[maxn];

void dfs_down(int node, int par)
{
    visited[node] = true;
    dp[node] = 0;

    for (int i = 0; i < g[node].size(); ++i)
    {
        if (g[node][i].first != par)
        {
            dfs_down(g[node][i].first, node);
            dp[node] = max(dp[node], g[node][i].second + dp[g[node][i].first]);
        }
    }
}

long long longest = 0;

long long dfs_up(int node, int par, long long up)
{
    long long result = max(up, dp[node]);
    longest = max(longest, dp[node] + up);

    long long max1 = 0;
    long long max2 = 0;

    for (int i = 0; i < g[node].size(); ++i)
    {
        int child = g[node][i].first;
        int edge = g[node][i].second;

        if (child == par)
        {
            continue;
        }

        if (dp[child] + edge > max1)
        {
            max2 = max1;
            max1 = dp[child] + edge;
        }
        else if (dp[child] + edge > max2)
        {
            max2 = dp[child] + edge;
        }
    }

    for (int i = 0; i < g[node].size(); ++i)
    {
        if (g[node][i].first == par)
        {
            continue;
        }

        int child = g[node][i].first;
        int edge = g[node][i].second;

        long long new_up = 0;

        if (dp[child] + edge == max1)
        {
            new_up = max(up, max2) + edge;
        }
        else
        {
            new_up = max(up, max1) + edge;
        }

        result = min(result, dfs_up(child, node, new_up));
    }

    return result;
}

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)
    {
        int x = A[i] + 1;
        int y = B[i] + 1;
        int w = T[i];

        g[x].push_back(make_pair(y, w));
        g[y].push_back(make_pair(x, w));
    }

    vector<long long> dists;

    for (int i = 1; i <= n; ++i)
    {
        if (visited[i] == false)
        {
            dfs_down(i, -1);
            dists.push_back(dfs_up(i, -1, 0));
        }
    }

    sort(dists.begin(), dists.end());

    if (dists.size() == 1)
    {
        return max(longest, dists[0]);
    }

    long long ans = max(longest, dists[dists.size() - 1] + dists[dists.size() - 2] + L);

    if (dists.size() >= 3)
    {
        ans = max(ans, dists[dists.size() - 2] + dists[dists[dists.size() - 3]] + 2 * L);
    }

    return ans;
}

/*int main()
{
    int A[8] = {0, 8, 2, 5, 5, 1, 1, 10};
    int B[8] = {8, 2, 7, 11, 1, 3, 9, 6};
    int T[8] = {4, 2, 4, 3, 7, 1, 5, 3};

    std::cout << travelTime(12, 8, 2, A, B, T) << std::endl;

    return 0;
}*/

Compilation message

dreaming.cpp: In function 'void dfs_down(int, int)':
dreaming.cpp:20:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for (int i = 0; i < g[node].size(); ++i)
      |                     ~~^~~~~~~~~~~~~~~~
dreaming.cpp: In function 'long long int dfs_up(int, int, long long int)':
dreaming.cpp:40:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for (int i = 0; i < g[node].size(); ++i)
      |                     ~~^~~~~~~~~~~~~~~~
dreaming.cpp:61:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |     for (int i = 0; i < g[node].size(); ++i)
      |                     ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 11292 KB Output is correct
2 Correct 30 ms 10948 KB Output is correct
3 Correct 22 ms 9764 KB Output is correct
4 Correct 5 ms 3832 KB Output is correct
5 Correct 5 ms 3404 KB Output is correct
6 Correct 8 ms 4564 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 17 ms 6256 KB Output is correct
9 Correct 20 ms 8276 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 29 ms 8868 KB Output is correct
12 Correct 32 ms 10028 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 1 ms 2644 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Correct 1 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 1 ms 2644 KB Output is correct
19 Correct 1 ms 2644 KB Output is correct
20 Correct 1 ms 2644 KB Output is correct
21 Correct 1 ms 2644 KB Output is correct
22 Correct 1 ms 2644 KB Output is correct
23 Correct 1 ms 2644 KB Output is correct
24 Correct 1 ms 2644 KB Output is correct
25 Correct 1 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 11292 KB Output is correct
2 Correct 30 ms 10948 KB Output is correct
3 Correct 22 ms 9764 KB Output is correct
4 Correct 5 ms 3832 KB Output is correct
5 Correct 5 ms 3404 KB Output is correct
6 Correct 8 ms 4564 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 17 ms 6256 KB Output is correct
9 Correct 20 ms 8276 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 29 ms 8868 KB Output is correct
12 Correct 32 ms 10028 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Correct 1 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
17 Correct 1 ms 2644 KB Output is correct
18 Correct 1 ms 2644 KB Output is correct
19 Correct 1 ms 2644 KB Output is correct
20 Correct 1 ms 2644 KB Output is correct
21 Correct 1 ms 2644 KB Output is correct
22 Correct 1 ms 2644 KB Output is correct
23 Correct 1 ms 2644 KB Output is correct
24 Correct 1 ms 2644 KB Output is correct
25 Correct 1 ms 2644 KB Output is correct
26 Correct 1 ms 2644 KB Output is correct
27 Correct 1 ms 2644 KB Output is correct
28 Correct 1 ms 2644 KB Output is correct
29 Correct 1 ms 2644 KB Output is correct
30 Correct 2 ms 2644 KB Output is correct
31 Correct 1 ms 2644 KB Output is correct
32 Correct 1 ms 2644 KB Output is correct
33 Correct 1 ms 2644 KB Output is correct
34 Correct 1 ms 2644 KB Output is correct
35 Correct 1 ms 2644 KB Output is correct
36 Correct 1 ms 2644 KB Output is correct
37 Correct 1 ms 2644 KB Output is correct
38 Correct 1 ms 2644 KB Output is correct
39 Correct 31 ms 11308 KB Output is correct
40 Correct 34 ms 10920 KB Output is correct
41 Correct 22 ms 9676 KB Output is correct
42 Correct 8 ms 3848 KB Output is correct
43 Correct 1 ms 2644 KB Output is correct
44 Correct 1 ms 2644 KB Output is correct
45 Correct 1 ms 2644 KB Output is correct
46 Correct 1 ms 2644 KB Output is correct
47 Correct 1 ms 2644 KB Output is correct
48 Correct 1 ms 2644 KB Output is correct
49 Correct 1 ms 2644 KB Output is correct
50 Correct 1 ms 2644 KB Output is correct
51 Correct 1 ms 2644 KB Output is correct
52 Correct 1 ms 2644 KB Output is correct
53 Correct 1 ms 2644 KB Output is correct
54 Correct 1 ms 2644 KB Output is correct
55 Correct 1 ms 2644 KB Output is correct
56 Correct 1 ms 2644 KB Output is correct
57 Correct 40 ms 8580 KB Output is correct
58 Correct 39 ms 8580 KB Output is correct
59 Correct 39 ms 8624 KB Output is correct
60 Correct 39 ms 8468 KB Output is correct
61 Correct 39 ms 8524 KB Output is correct
62 Correct 38 ms 8524 KB Output is correct
63 Correct 38 ms 8328 KB Output is correct
64 Correct 36 ms 8268 KB Output is correct
65 Correct 37 ms 8268 KB Output is correct
66 Correct 38 ms 8272 KB Output is correct
67 Correct 38 ms 8600 KB Output is correct
68 Correct 38 ms 8520 KB Output is correct
69 Correct 41 ms 8580 KB Output is correct
70 Correct 39 ms 8600 KB Output is correct
71 Correct 1 ms 2644 KB Output is correct
72 Correct 2 ms 2860 KB Output is correct
73 Correct 3 ms 2772 KB Output is correct
74 Correct 2 ms 2772 KB Output is correct
75 Correct 3 ms 2900 KB Output is correct
76 Correct 2 ms 2772 KB Output is correct
77 Correct 2 ms 2772 KB Output is correct
78 Correct 2 ms 2772 KB Output is correct
79 Correct 2 ms 2772 KB Output is correct
80 Correct 40 ms 8508 KB Output is correct
81 Correct 41 ms 8572 KB Output is correct
82 Correct 39 ms 8396 KB Output is correct
83 Correct 38 ms 8436 KB Output is correct
84 Correct 2 ms 2772 KB Output is correct
85 Correct 2 ms 2772 KB Output is correct
86 Correct 2 ms 2772 KB Output is correct
87 Correct 2 ms 2772 KB Output is correct
88 Correct 2 ms 2772 KB Output is correct
89 Correct 3 ms 2772 KB Output is correct
90 Correct 2 ms 2772 KB Output is correct
91 Correct 3 ms 2772 KB Output is correct
92 Correct 2 ms 2772 KB Output is correct
93 Correct 3 ms 2772 KB Output is correct
94 Correct 1 ms 2644 KB Output is correct
95 Correct 1 ms 2644 KB Output is correct
96 Correct 1 ms 2644 KB Output is correct
97 Correct 1 ms 2644 KB Output is correct
98 Correct 1 ms 2644 KB Output is correct
99 Correct 1 ms 2644 KB Output is correct
100 Correct 1 ms 2644 KB Output is correct
101 Correct 1 ms 2644 KB Output is correct
102 Correct 1 ms 2644 KB Output is correct
103 Correct 1 ms 2644 KB Output is correct
104 Correct 5 ms 3284 KB Output is correct
105 Correct 8 ms 4560 KB Output is correct
106 Correct 2 ms 2644 KB Output is correct
107 Correct 19 ms 6196 KB Output is correct
108 Correct 21 ms 8276 KB Output is correct
109 Correct 2 ms 2712 KB Output is correct
110 Correct 29 ms 8800 KB Output is correct
111 Correct 34 ms 10028 KB Output is correct
112 Correct 2 ms 2644 KB Output is correct
113 Correct 55 ms 15492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 6360 KB Output is correct
2 Incorrect 14 ms 6412 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 1 ms 2644 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Correct 1 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 1 ms 2644 KB Output is correct
19 Correct 1 ms 2644 KB Output is correct
20 Correct 1 ms 2644 KB Output is correct
21 Correct 1 ms 2644 KB Output is correct
22 Correct 1 ms 2644 KB Output is correct
23 Correct 1 ms 2644 KB Output is correct
24 Correct 1 ms 2644 KB Output is correct
25 Correct 1 ms 2644 KB Output is correct
26 Correct 2 ms 2644 KB Output is correct
27 Correct 2 ms 2772 KB Output is correct
28 Correct 2 ms 2772 KB Output is correct
29 Correct 1 ms 2644 KB Output is correct
30 Correct 2 ms 2772 KB Output is correct
31 Correct 2 ms 2772 KB Output is correct
32 Runtime error 4 ms 5332 KB Execution killed with signal 11
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 11292 KB Output is correct
2 Correct 30 ms 10948 KB Output is correct
3 Correct 22 ms 9764 KB Output is correct
4 Correct 5 ms 3832 KB Output is correct
5 Correct 5 ms 3404 KB Output is correct
6 Correct 8 ms 4564 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 17 ms 6256 KB Output is correct
9 Correct 20 ms 8276 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 29 ms 8868 KB Output is correct
12 Correct 32 ms 10028 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Correct 1 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
17 Correct 1 ms 2644 KB Output is correct
18 Correct 1 ms 2644 KB Output is correct
19 Correct 1 ms 2644 KB Output is correct
20 Correct 1 ms 2644 KB Output is correct
21 Correct 1 ms 2644 KB Output is correct
22 Correct 1 ms 2644 KB Output is correct
23 Correct 1 ms 2644 KB Output is correct
24 Correct 1 ms 2644 KB Output is correct
25 Correct 1 ms 2644 KB Output is correct
26 Correct 1 ms 2644 KB Output is correct
27 Correct 1 ms 2644 KB Output is correct
28 Correct 1 ms 2644 KB Output is correct
29 Correct 1 ms 2644 KB Output is correct
30 Correct 2 ms 2644 KB Output is correct
31 Correct 1 ms 2644 KB Output is correct
32 Correct 1 ms 2644 KB Output is correct
33 Correct 1 ms 2644 KB Output is correct
34 Correct 1 ms 2644 KB Output is correct
35 Correct 1 ms 2644 KB Output is correct
36 Correct 1 ms 2644 KB Output is correct
37 Correct 1 ms 2644 KB Output is correct
38 Correct 1 ms 2644 KB Output is correct
39 Correct 31 ms 11308 KB Output is correct
40 Correct 34 ms 10920 KB Output is correct
41 Correct 22 ms 9676 KB Output is correct
42 Correct 8 ms 3848 KB Output is correct
43 Correct 1 ms 2644 KB Output is correct
44 Correct 1 ms 2644 KB Output is correct
45 Correct 1 ms 2644 KB Output is correct
46 Correct 1 ms 2644 KB Output is correct
47 Correct 1 ms 2644 KB Output is correct
48 Correct 1 ms 2644 KB Output is correct
49 Correct 1 ms 2644 KB Output is correct
50 Correct 1 ms 2644 KB Output is correct
51 Correct 1 ms 2644 KB Output is correct
52 Correct 1 ms 2644 KB Output is correct
53 Correct 1 ms 2644 KB Output is correct
54 Correct 1 ms 2644 KB Output is correct
55 Correct 1 ms 2644 KB Output is correct
56 Correct 1 ms 2644 KB Output is correct
57 Correct 40 ms 8580 KB Output is correct
58 Correct 39 ms 8580 KB Output is correct
59 Correct 39 ms 8624 KB Output is correct
60 Correct 39 ms 8468 KB Output is correct
61 Correct 39 ms 8524 KB Output is correct
62 Correct 38 ms 8524 KB Output is correct
63 Correct 38 ms 8328 KB Output is correct
64 Correct 36 ms 8268 KB Output is correct
65 Correct 37 ms 8268 KB Output is correct
66 Correct 38 ms 8272 KB Output is correct
67 Correct 38 ms 8600 KB Output is correct
68 Correct 38 ms 8520 KB Output is correct
69 Correct 41 ms 8580 KB Output is correct
70 Correct 39 ms 8600 KB Output is correct
71 Correct 1 ms 2644 KB Output is correct
72 Correct 2 ms 2860 KB Output is correct
73 Correct 3 ms 2772 KB Output is correct
74 Correct 2 ms 2772 KB Output is correct
75 Correct 3 ms 2900 KB Output is correct
76 Correct 2 ms 2772 KB Output is correct
77 Correct 2 ms 2772 KB Output is correct
78 Correct 2 ms 2772 KB Output is correct
79 Correct 2 ms 2772 KB Output is correct
80 Correct 40 ms 8508 KB Output is correct
81 Correct 41 ms 8572 KB Output is correct
82 Correct 39 ms 8396 KB Output is correct
83 Correct 38 ms 8436 KB Output is correct
84 Correct 2 ms 2772 KB Output is correct
85 Correct 2 ms 2772 KB Output is correct
86 Correct 2 ms 2772 KB Output is correct
87 Correct 2 ms 2772 KB Output is correct
88 Correct 2 ms 2772 KB Output is correct
89 Correct 3 ms 2772 KB Output is correct
90 Correct 2 ms 2772 KB Output is correct
91 Correct 3 ms 2772 KB Output is correct
92 Correct 2 ms 2772 KB Output is correct
93 Correct 3 ms 2772 KB Output is correct
94 Correct 1 ms 2644 KB Output is correct
95 Correct 1 ms 2644 KB Output is correct
96 Correct 1 ms 2644 KB Output is correct
97 Correct 1 ms 2644 KB Output is correct
98 Correct 1 ms 2644 KB Output is correct
99 Correct 1 ms 2644 KB Output is correct
100 Correct 1 ms 2644 KB Output is correct
101 Correct 1 ms 2644 KB Output is correct
102 Correct 1 ms 2644 KB Output is correct
103 Correct 1 ms 2644 KB Output is correct
104 Correct 5 ms 3284 KB Output is correct
105 Correct 8 ms 4560 KB Output is correct
106 Correct 2 ms 2644 KB Output is correct
107 Correct 19 ms 6196 KB Output is correct
108 Correct 21 ms 8276 KB Output is correct
109 Correct 2 ms 2712 KB Output is correct
110 Correct 29 ms 8800 KB Output is correct
111 Correct 34 ms 10028 KB Output is correct
112 Correct 2 ms 2644 KB Output is correct
113 Correct 55 ms 15492 KB Output is correct
114 Correct 15 ms 6360 KB Output is correct
115 Incorrect 14 ms 6412 KB Output isn't correct
116 Halted 0 ms 0 KB -