답안 #168005

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
168005 2019-12-11T06:57:32 Z davitmarg 꿈 (IOI13_dreaming) C++17
47 / 100
166 ms 28152 KB
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000009ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;

const int N = 100005;

#ifndef death
#include "dreaming.h"
#endif

int n, used[N], color;
LL x, ans[N], ANS;
vector<pair<int, LL>> g[N];
vector<LL> dp[N];

void dfs(int v, int p = -1)
{
    used[v] = color;
    dp[v].PB(0);
    dp[v].PB(0);
    for (int i = 0; i < g[v].size(); i++)
    {
        int to = g[v][i].first;
        LL d = g[v][i].second;
        if (to == p)
            continue;
        dfs(to, v);
        dp[v].PB(dp[to][0] + d);
    }
    sort(all(dp[v]));
    reverse(all(dp[v]));
    ANS = max(dp[v][0] + dp[v][1], ANS);
}

void dfs2(int v, int p, LL dist)
{
    ans[v] = max(dp[v][0], dist);

    for (int i = 0; i < g[v].size(); i++)
    {
        int to = g[v][i].first;
        LL d = g[v][i].second;
        if (to == p)
            continue;

        LL newdist;

        if (dp[to][0] + d == dp[v][0])
            newdist = max(dist, dp[v][1]) + d;
        else
            newdist = max(dist, dp[v][0]) + d;
        dfs2(to, v, newdist);
        ans[v] = min(ans[v], ans[to]);
    }
}

int travelTime(int N, int M, int L, int A[], int B[], int T[])
{
    n = N;
    x = L;
    while (M--)
    {
        g[A[M]].PB(MP(B[M], T[M]));
        g[B[M]].PB(MP(A[M], T[M]));
    }
    vector<LL> res;
    for (int i = 0; i < n; i++)
    {
        if (used[i])
            continue;
        color++;
        dfs(i);
        dfs2(i, -1, 0);
        //cout << ans[i] << " !\n";
        res.PB(ans[i]);
    }
    sort(all(res));
    reverse(all(res));
    if (res.size() > 1)
    {
        ANS = max(x + res[0] + res[1], ANS);
        // if (res.size() > 2)
        //     ANS = max(ANS, res[1] + res[2] + x + x);
    }
    return ANS;
}

#ifdef death

int main()
{
    int N, M, L, A[102], B[102], D[102];
    cin >> N >> M >> L;
    for (int i = 0; i < M; i++)
        cin >> A[i] >> B[i] >> D[i];
    cout << travelTime(N, M, L, A, B, D) << endl;
    return 0;
}

#endif

/*


7 5 1
0 1 5
1 2 3
2 3 2
1 4 4
4 5 2

8 6 100
0 1 10
1 2 15
2 7 11
3 4 3
4 5 332
5 6 3

12 8 2 
0 8 4
8 2 2
2 7 4
5 11 3
5 1 7
1 3 1
1 9 5
10 6 3

*/

Compilation message

dreaming.cpp: In function 'void dfs(int, int)':
dreaming.cpp:42:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < g[v].size(); i++)
                     ~~^~~~~~~~~~~~~
dreaming.cpp: In function 'void dfs2(int, int, long long int)':
dreaming.cpp:60:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < g[v].size(); i++)
                     ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 110 ms 21752 KB Output is correct
2 Correct 101 ms 21368 KB Output is correct
3 Correct 69 ms 17912 KB Output is correct
4 Correct 19 ms 7612 KB Output is correct
5 Correct 17 ms 6648 KB Output is correct
6 Correct 28 ms 8824 KB Output is correct
7 Correct 6 ms 5112 KB Output is correct
8 Correct 52 ms 12280 KB Output is correct
9 Correct 67 ms 15480 KB Output is correct
10 Correct 6 ms 5112 KB Output is correct
11 Correct 95 ms 17784 KB Output is correct
12 Correct 123 ms 19900 KB Output is correct
13 Correct 6 ms 5240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 110 ms 21752 KB Output is correct
2 Correct 101 ms 21368 KB Output is correct
3 Correct 69 ms 17912 KB Output is correct
4 Correct 19 ms 7612 KB Output is correct
5 Correct 17 ms 6648 KB Output is correct
6 Correct 28 ms 8824 KB Output is correct
7 Correct 6 ms 5112 KB Output is correct
8 Correct 52 ms 12280 KB Output is correct
9 Correct 67 ms 15480 KB Output is correct
10 Correct 6 ms 5112 KB Output is correct
11 Correct 95 ms 17784 KB Output is correct
12 Correct 123 ms 19900 KB Output is correct
13 Correct 6 ms 5240 KB Output is correct
14 Correct 6 ms 5112 KB Output is correct
15 Correct 7 ms 5112 KB Output is correct
16 Correct 6 ms 5084 KB Output is correct
17 Correct 6 ms 5068 KB Output is correct
18 Correct 6 ms 5112 KB Output is correct
19 Correct 6 ms 5112 KB Output is correct
20 Correct 6 ms 4984 KB Output is correct
21 Correct 6 ms 4988 KB Output is correct
22 Correct 6 ms 5112 KB Output is correct
23 Correct 6 ms 4984 KB Output is correct
24 Correct 6 ms 5112 KB Output is correct
25 Correct 7 ms 5112 KB Output is correct
26 Correct 15 ms 4984 KB Output is correct
27 Correct 6 ms 5112 KB Output is correct
28 Correct 6 ms 5084 KB Output is correct
29 Correct 7 ms 4984 KB Output is correct
30 Correct 6 ms 5112 KB Output is correct
31 Correct 7 ms 4984 KB Output is correct
32 Correct 6 ms 4984 KB Output is correct
33 Correct 6 ms 4984 KB Output is correct
34 Correct 6 ms 5112 KB Output is correct
35 Correct 6 ms 4984 KB Output is correct
36 Correct 6 ms 4984 KB Output is correct
37 Correct 6 ms 5112 KB Output is correct
38 Correct 6 ms 4984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 110 ms 21752 KB Output is correct
2 Correct 101 ms 21368 KB Output is correct
3 Correct 69 ms 17912 KB Output is correct
4 Correct 19 ms 7612 KB Output is correct
5 Correct 17 ms 6648 KB Output is correct
6 Correct 28 ms 8824 KB Output is correct
7 Correct 6 ms 5112 KB Output is correct
8 Correct 52 ms 12280 KB Output is correct
9 Correct 67 ms 15480 KB Output is correct
10 Correct 6 ms 5112 KB Output is correct
11 Correct 95 ms 17784 KB Output is correct
12 Correct 123 ms 19900 KB Output is correct
13 Correct 6 ms 5240 KB Output is correct
14 Correct 6 ms 5112 KB Output is correct
15 Correct 7 ms 5112 KB Output is correct
16 Correct 6 ms 5084 KB Output is correct
17 Correct 6 ms 5068 KB Output is correct
18 Correct 6 ms 5112 KB Output is correct
19 Correct 6 ms 5112 KB Output is correct
20 Correct 6 ms 4984 KB Output is correct
21 Correct 6 ms 4988 KB Output is correct
22 Correct 6 ms 5112 KB Output is correct
23 Correct 6 ms 4984 KB Output is correct
24 Correct 6 ms 5112 KB Output is correct
25 Correct 7 ms 5112 KB Output is correct
26 Correct 15 ms 4984 KB Output is correct
27 Correct 6 ms 5112 KB Output is correct
28 Correct 6 ms 5084 KB Output is correct
29 Correct 7 ms 4984 KB Output is correct
30 Correct 6 ms 5112 KB Output is correct
31 Correct 7 ms 4984 KB Output is correct
32 Correct 6 ms 4984 KB Output is correct
33 Correct 6 ms 4984 KB Output is correct
34 Correct 6 ms 5112 KB Output is correct
35 Correct 6 ms 4984 KB Output is correct
36 Correct 6 ms 4984 KB Output is correct
37 Correct 6 ms 5112 KB Output is correct
38 Correct 6 ms 4984 KB Output is correct
39 Correct 97 ms 21752 KB Output is correct
40 Correct 105 ms 21344 KB Output is correct
41 Correct 69 ms 17788 KB Output is correct
42 Correct 18 ms 7544 KB Output is correct
43 Correct 6 ms 4984 KB Output is correct
44 Correct 6 ms 5112 KB Output is correct
45 Correct 6 ms 4984 KB Output is correct
46 Correct 6 ms 4984 KB Output is correct
47 Correct 6 ms 4984 KB Output is correct
48 Correct 6 ms 4984 KB Output is correct
49 Correct 6 ms 5112 KB Output is correct
50 Correct 6 ms 5112 KB Output is correct
51 Correct 6 ms 4984 KB Output is correct
52 Correct 6 ms 4984 KB Output is correct
53 Correct 6 ms 5112 KB Output is correct
54 Correct 6 ms 4984 KB Output is correct
55 Correct 6 ms 5084 KB Output is correct
56 Correct 6 ms 5112 KB Output is correct
57 Correct 131 ms 18240 KB Output is correct
58 Correct 143 ms 18040 KB Output is correct
59 Correct 126 ms 18296 KB Output is correct
60 Correct 128 ms 18296 KB Output is correct
61 Correct 128 ms 18456 KB Output is correct
62 Correct 127 ms 18424 KB Output is correct
63 Correct 116 ms 18168 KB Output is correct
64 Correct 134 ms 18168 KB Output is correct
65 Correct 136 ms 18552 KB Output is correct
66 Correct 157 ms 18424 KB Output is correct
67 Correct 133 ms 18296 KB Output is correct
68 Correct 137 ms 18296 KB Output is correct
69 Correct 130 ms 18600 KB Output is correct
70 Correct 132 ms 18596 KB Output is correct
71 Correct 6 ms 4984 KB Output is correct
72 Correct 8 ms 5368 KB Output is correct
73 Correct 8 ms 5496 KB Output is correct
74 Correct 9 ms 5496 KB Output is correct
75 Correct 8 ms 5372 KB Output is correct
76 Correct 8 ms 5368 KB Output is correct
77 Correct 8 ms 5368 KB Output is correct
78 Correct 9 ms 5496 KB Output is correct
79 Correct 8 ms 5400 KB Output is correct
80 Correct 134 ms 18168 KB Output is correct
81 Correct 129 ms 18296 KB Output is correct
82 Correct 126 ms 18424 KB Output is correct
83 Correct 130 ms 18424 KB Output is correct
84 Correct 8 ms 5368 KB Output is correct
85 Correct 8 ms 5372 KB Output is correct
86 Correct 8 ms 5368 KB Output is correct
87 Correct 8 ms 5368 KB Output is correct
88 Correct 8 ms 5368 KB Output is correct
89 Correct 8 ms 5368 KB Output is correct
90 Correct 8 ms 5368 KB Output is correct
91 Correct 8 ms 5496 KB Output is correct
92 Correct 8 ms 5368 KB Output is correct
93 Correct 8 ms 5368 KB Output is correct
94 Correct 6 ms 4984 KB Output is correct
95 Correct 6 ms 5084 KB Output is correct
96 Correct 6 ms 5112 KB Output is correct
97 Correct 6 ms 4984 KB Output is correct
98 Correct 6 ms 4984 KB Output is correct
99 Correct 6 ms 5112 KB Output is correct
100 Correct 6 ms 4984 KB Output is correct
101 Correct 6 ms 5112 KB Output is correct
102 Correct 6 ms 4984 KB Output is correct
103 Correct 6 ms 4984 KB Output is correct
104 Correct 16 ms 6620 KB Output is correct
105 Correct 27 ms 8824 KB Output is correct
106 Correct 6 ms 5112 KB Output is correct
107 Correct 48 ms 12280 KB Output is correct
108 Correct 65 ms 15608 KB Output is correct
109 Correct 6 ms 5112 KB Output is correct
110 Correct 104 ms 17896 KB Output is correct
111 Correct 122 ms 19832 KB Output is correct
112 Correct 7 ms 5240 KB Output is correct
113 Correct 166 ms 28152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 12780 KB Output is correct
2 Incorrect 52 ms 12784 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 110 ms 21752 KB Output is correct
2 Correct 101 ms 21368 KB Output is correct
3 Correct 69 ms 17912 KB Output is correct
4 Correct 19 ms 7612 KB Output is correct
5 Correct 17 ms 6648 KB Output is correct
6 Correct 28 ms 8824 KB Output is correct
7 Correct 6 ms 5112 KB Output is correct
8 Correct 52 ms 12280 KB Output is correct
9 Correct 67 ms 15480 KB Output is correct
10 Correct 6 ms 5112 KB Output is correct
11 Correct 95 ms 17784 KB Output is correct
12 Correct 123 ms 19900 KB Output is correct
13 Correct 6 ms 5240 KB Output is correct
14 Correct 7 ms 5240 KB Output is correct
15 Correct 7 ms 5240 KB Output is correct
16 Correct 8 ms 5496 KB Output is correct
17 Correct 6 ms 5112 KB Output is correct
18 Correct 8 ms 5240 KB Output is correct
19 Correct 8 ms 5368 KB Output is correct
20 Incorrect 7 ms 5240 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 110 ms 21752 KB Output is correct
2 Correct 101 ms 21368 KB Output is correct
3 Correct 69 ms 17912 KB Output is correct
4 Correct 19 ms 7612 KB Output is correct
5 Correct 17 ms 6648 KB Output is correct
6 Correct 28 ms 8824 KB Output is correct
7 Correct 6 ms 5112 KB Output is correct
8 Correct 52 ms 12280 KB Output is correct
9 Correct 67 ms 15480 KB Output is correct
10 Correct 6 ms 5112 KB Output is correct
11 Correct 95 ms 17784 KB Output is correct
12 Correct 123 ms 19900 KB Output is correct
13 Correct 6 ms 5240 KB Output is correct
14 Correct 6 ms 5112 KB Output is correct
15 Correct 7 ms 5112 KB Output is correct
16 Correct 6 ms 5084 KB Output is correct
17 Correct 6 ms 5068 KB Output is correct
18 Correct 6 ms 5112 KB Output is correct
19 Correct 6 ms 5112 KB Output is correct
20 Correct 6 ms 4984 KB Output is correct
21 Correct 6 ms 4988 KB Output is correct
22 Correct 6 ms 5112 KB Output is correct
23 Correct 6 ms 4984 KB Output is correct
24 Correct 6 ms 5112 KB Output is correct
25 Correct 7 ms 5112 KB Output is correct
26 Correct 15 ms 4984 KB Output is correct
27 Correct 6 ms 5112 KB Output is correct
28 Correct 6 ms 5084 KB Output is correct
29 Correct 7 ms 4984 KB Output is correct
30 Correct 6 ms 5112 KB Output is correct
31 Correct 7 ms 4984 KB Output is correct
32 Correct 6 ms 4984 KB Output is correct
33 Correct 6 ms 4984 KB Output is correct
34 Correct 6 ms 5112 KB Output is correct
35 Correct 6 ms 4984 KB Output is correct
36 Correct 6 ms 4984 KB Output is correct
37 Correct 6 ms 5112 KB Output is correct
38 Correct 6 ms 4984 KB Output is correct
39 Correct 97 ms 21752 KB Output is correct
40 Correct 105 ms 21344 KB Output is correct
41 Correct 69 ms 17788 KB Output is correct
42 Correct 18 ms 7544 KB Output is correct
43 Correct 6 ms 4984 KB Output is correct
44 Correct 6 ms 5112 KB Output is correct
45 Correct 6 ms 4984 KB Output is correct
46 Correct 6 ms 4984 KB Output is correct
47 Correct 6 ms 4984 KB Output is correct
48 Correct 6 ms 4984 KB Output is correct
49 Correct 6 ms 5112 KB Output is correct
50 Correct 6 ms 5112 KB Output is correct
51 Correct 6 ms 4984 KB Output is correct
52 Correct 6 ms 4984 KB Output is correct
53 Correct 6 ms 5112 KB Output is correct
54 Correct 6 ms 4984 KB Output is correct
55 Correct 6 ms 5084 KB Output is correct
56 Correct 6 ms 5112 KB Output is correct
57 Correct 131 ms 18240 KB Output is correct
58 Correct 143 ms 18040 KB Output is correct
59 Correct 126 ms 18296 KB Output is correct
60 Correct 128 ms 18296 KB Output is correct
61 Correct 128 ms 18456 KB Output is correct
62 Correct 127 ms 18424 KB Output is correct
63 Correct 116 ms 18168 KB Output is correct
64 Correct 134 ms 18168 KB Output is correct
65 Correct 136 ms 18552 KB Output is correct
66 Correct 157 ms 18424 KB Output is correct
67 Correct 133 ms 18296 KB Output is correct
68 Correct 137 ms 18296 KB Output is correct
69 Correct 130 ms 18600 KB Output is correct
70 Correct 132 ms 18596 KB Output is correct
71 Correct 6 ms 4984 KB Output is correct
72 Correct 8 ms 5368 KB Output is correct
73 Correct 8 ms 5496 KB Output is correct
74 Correct 9 ms 5496 KB Output is correct
75 Correct 8 ms 5372 KB Output is correct
76 Correct 8 ms 5368 KB Output is correct
77 Correct 8 ms 5368 KB Output is correct
78 Correct 9 ms 5496 KB Output is correct
79 Correct 8 ms 5400 KB Output is correct
80 Correct 134 ms 18168 KB Output is correct
81 Correct 129 ms 18296 KB Output is correct
82 Correct 126 ms 18424 KB Output is correct
83 Correct 130 ms 18424 KB Output is correct
84 Correct 8 ms 5368 KB Output is correct
85 Correct 8 ms 5372 KB Output is correct
86 Correct 8 ms 5368 KB Output is correct
87 Correct 8 ms 5368 KB Output is correct
88 Correct 8 ms 5368 KB Output is correct
89 Correct 8 ms 5368 KB Output is correct
90 Correct 8 ms 5368 KB Output is correct
91 Correct 8 ms 5496 KB Output is correct
92 Correct 8 ms 5368 KB Output is correct
93 Correct 8 ms 5368 KB Output is correct
94 Correct 6 ms 4984 KB Output is correct
95 Correct 6 ms 5084 KB Output is correct
96 Correct 6 ms 5112 KB Output is correct
97 Correct 6 ms 4984 KB Output is correct
98 Correct 6 ms 4984 KB Output is correct
99 Correct 6 ms 5112 KB Output is correct
100 Correct 6 ms 4984 KB Output is correct
101 Correct 6 ms 5112 KB Output is correct
102 Correct 6 ms 4984 KB Output is correct
103 Correct 6 ms 4984 KB Output is correct
104 Correct 16 ms 6620 KB Output is correct
105 Correct 27 ms 8824 KB Output is correct
106 Correct 6 ms 5112 KB Output is correct
107 Correct 48 ms 12280 KB Output is correct
108 Correct 65 ms 15608 KB Output is correct
109 Correct 6 ms 5112 KB Output is correct
110 Correct 104 ms 17896 KB Output is correct
111 Correct 122 ms 19832 KB Output is correct
112 Correct 7 ms 5240 KB Output is correct
113 Correct 166 ms 28152 KB Output is correct
114 Correct 53 ms 12780 KB Output is correct
115 Incorrect 52 ms 12784 KB Output isn't correct
116 Halted 0 ms 0 KB -