답안 #842945

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
842945 2023-09-03T13:43:25 Z 12345678 꿈 (IOI13_dreaming) C++17
65 / 100
75 ms 30152 KB
#include "dreaming.h"
#include <bits/stdc++.h>

using namespace std;

const int nx=1e5+5;
int mx[nx], mxr[nx], nxt=0, mx1=INT_MAX, mx2=INT_MAX, ans, cmx, cnt;
bool vs[nx];
vector<vector<pair<int, int>>> d(nx);
vector<int> b(nx), c;

void dfs(int u, int p)
{
    vs[u]=1; c.push_back(u);
    for (auto [v, w]:d[u])
    {
        if (v==p) continue;
        dfs(v, u);
        mx[u]=max(mx[u], mx[v]+w);
    }
}

void dfs2(int u, int p)
{
    vector<int> pf(d[u].size()+2), sf(d[u].size()+2);
    pf[0]=mxr[u];
    for (int i=d[u].size()-1; i>=0; i--)
    {
        sf[i+1]=sf[i+2];
        if (d[u][i].first==p) continue;
        sf[i+1]=max(sf[i+1], d[u][i].second+mx[d[u][i].first]);
    }
    for (int i=0; i<d[u].size(); i++)
    {
        pf[i+1]=pf[i];
        if (d[u][i].first==p) continue;
        pf[i+1]=max(pf[i+1], d[u][i].second+mx[d[u][i].first]);
        mxr[d[u][i].first]=max(pf[i], sf[i+2])+d[u][i].second;
    }
    for (auto [v, w]:d[u]) if (v!=p) dfs2(v, u);
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    if (N==1) return 0;
    if (N==2&&M==1) return T[0];
    if (N==2) return L;
    for (int i=0; i<M; i++) d[A[i]].push_back({B[i], T[i]}), d[B[i]].push_back({A[i], T[i]});
    for (int i=0; i<N; i++)
    {
        if (vs[i]) continue;
        c.clear();
        dfs(i, i); dfs2(i, i);
        cmx=INT_MAX;
        for (auto x:c) cmx=min(cmx, max(mx[x], mxr[x]));
        b[cnt++]=cmx;
    }
    for (int i=0; i<N; i++) ans=max(ans, mx[i]+mxr[i]);
    sort(b.begin(), b.end());
    reverse(b.begin(), b.end());
    if (cnt==1) return b[0];
    if (cnt==2) return max(ans, b[0]+b[1]+L);
    return max(ans, max(b[0]+L+b[1], b[1]+2*L+b[2]));
}

Compilation message

dreaming.cpp: In function 'void dfs2(int, int)':
dreaming.cpp:33:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     for (int i=0; i<d[u].size(); i++)
      |                   ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 19152 KB Output is correct
2 Correct 44 ms 18376 KB Output is correct
3 Correct 36 ms 17612 KB Output is correct
4 Correct 8 ms 5464 KB Output is correct
5 Correct 7 ms 4188 KB Output is correct
6 Correct 13 ms 6904 KB Output is correct
7 Correct 3 ms 3160 KB Output is correct
8 Correct 22 ms 9616 KB Output is correct
9 Correct 34 ms 14292 KB Output is correct
10 Correct 3 ms 3160 KB Output is correct
11 Correct 45 ms 14268 KB Output is correct
12 Correct 42 ms 16592 KB Output is correct
13 Correct 3 ms 3164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3160 KB Output is correct
2 Correct 3 ms 3160 KB Output is correct
3 Correct 2 ms 3164 KB Output is correct
4 Correct 3 ms 3160 KB Output is correct
5 Correct 3 ms 3160 KB Output is correct
6 Correct 3 ms 3160 KB Output is correct
7 Correct 2 ms 3164 KB Output is correct
8 Correct 3 ms 3164 KB Output is correct
9 Correct 4 ms 3164 KB Output is correct
10 Correct 3 ms 3164 KB Output is correct
11 Correct 3 ms 3160 KB Output is correct
12 Correct 4 ms 3216 KB Output is correct
13 Correct 3 ms 3160 KB Output is correct
14 Correct 3 ms 3164 KB Output is correct
15 Correct 2 ms 3416 KB Output is correct
16 Correct 3 ms 3416 KB Output is correct
17 Correct 3 ms 3160 KB Output is correct
18 Correct 3 ms 3160 KB Output is correct
19 Correct 3 ms 3160 KB Output is correct
20 Correct 3 ms 3160 KB Output is correct
21 Correct 4 ms 3164 KB Output is correct
22 Correct 3 ms 3160 KB Output is correct
23 Correct 3 ms 3160 KB Output is correct
24 Correct 3 ms 3164 KB Output is correct
25 Correct 3 ms 3160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 19152 KB Output is correct
2 Correct 44 ms 18376 KB Output is correct
3 Correct 36 ms 17612 KB Output is correct
4 Correct 8 ms 5464 KB Output is correct
5 Correct 7 ms 4188 KB Output is correct
6 Correct 13 ms 6904 KB Output is correct
7 Correct 3 ms 3160 KB Output is correct
8 Correct 22 ms 9616 KB Output is correct
9 Correct 34 ms 14292 KB Output is correct
10 Correct 3 ms 3160 KB Output is correct
11 Correct 45 ms 14268 KB Output is correct
12 Correct 42 ms 16592 KB Output is correct
13 Correct 3 ms 3164 KB Output is correct
14 Correct 4 ms 3160 KB Output is correct
15 Correct 3 ms 3160 KB Output is correct
16 Correct 2 ms 3164 KB Output is correct
17 Correct 3 ms 3160 KB Output is correct
18 Correct 3 ms 3160 KB Output is correct
19 Correct 3 ms 3160 KB Output is correct
20 Correct 2 ms 3164 KB Output is correct
21 Correct 3 ms 3164 KB Output is correct
22 Correct 4 ms 3164 KB Output is correct
23 Correct 3 ms 3164 KB Output is correct
24 Correct 3 ms 3160 KB Output is correct
25 Correct 4 ms 3216 KB Output is correct
26 Correct 3 ms 3160 KB Output is correct
27 Correct 3 ms 3164 KB Output is correct
28 Correct 2 ms 3416 KB Output is correct
29 Correct 3 ms 3416 KB Output is correct
30 Correct 3 ms 3160 KB Output is correct
31 Correct 3 ms 3160 KB Output is correct
32 Correct 3 ms 3160 KB Output is correct
33 Correct 3 ms 3160 KB Output is correct
34 Correct 4 ms 3164 KB Output is correct
35 Correct 3 ms 3160 KB Output is correct
36 Correct 3 ms 3160 KB Output is correct
37 Correct 3 ms 3164 KB Output is correct
38 Correct 3 ms 3160 KB Output is correct
39 Correct 54 ms 19152 KB Output is correct
40 Correct 55 ms 18308 KB Output is correct
41 Correct 43 ms 17612 KB Output is correct
42 Correct 8 ms 5464 KB Output is correct
43 Correct 3 ms 3160 KB Output is correct
44 Correct 3 ms 3416 KB Output is correct
45 Correct 3 ms 3160 KB Output is correct
46 Correct 3 ms 3164 KB Output is correct
47 Correct 4 ms 3160 KB Output is correct
48 Correct 3 ms 3420 KB Output is correct
49 Correct 3 ms 3160 KB Output is correct
50 Correct 3 ms 3164 KB Output is correct
51 Correct 3 ms 3160 KB Output is correct
52 Correct 2 ms 3160 KB Output is correct
53 Correct 3 ms 3160 KB Output is correct
54 Correct 3 ms 3164 KB Output is correct
55 Correct 3 ms 3160 KB Output is correct
56 Correct 3 ms 3160 KB Output is correct
57 Correct 49 ms 9672 KB Output is correct
58 Correct 60 ms 9424 KB Output is correct
59 Correct 57 ms 9672 KB Output is correct
60 Correct 47 ms 9512 KB Output is correct
61 Correct 53 ms 9420 KB Output is correct
62 Correct 46 ms 9304 KB Output is correct
63 Correct 43 ms 9392 KB Output is correct
64 Correct 42 ms 9424 KB Output is correct
65 Correct 45 ms 9424 KB Output is correct
66 Correct 43 ms 9168 KB Output is correct
67 Correct 59 ms 9676 KB Output is correct
68 Correct 54 ms 9672 KB Output is correct
69 Correct 54 ms 9420 KB Output is correct
70 Correct 48 ms 9512 KB Output is correct
71 Correct 2 ms 3160 KB Output is correct
72 Correct 4 ms 3416 KB Output is correct
73 Correct 5 ms 3416 KB Output is correct
74 Correct 4 ms 3416 KB Output is correct
75 Correct 4 ms 3160 KB Output is correct
76 Correct 4 ms 3208 KB Output is correct
77 Correct 4 ms 3420 KB Output is correct
78 Correct 4 ms 3420 KB Output is correct
79 Correct 5 ms 3416 KB Output is correct
80 Correct 57 ms 9680 KB Output is correct
81 Correct 45 ms 9428 KB Output is correct
82 Correct 50 ms 9424 KB Output is correct
83 Correct 47 ms 9416 KB Output is correct
84 Correct 3 ms 3160 KB Output is correct
85 Correct 5 ms 3416 KB Output is correct
86 Correct 3 ms 3160 KB Output is correct
87 Correct 4 ms 3160 KB Output is correct
88 Correct 4 ms 3164 KB Output is correct
89 Correct 5 ms 3416 KB Output is correct
90 Correct 4 ms 3164 KB Output is correct
91 Correct 6 ms 3160 KB Output is correct
92 Correct 4 ms 3160 KB Output is correct
93 Correct 5 ms 3160 KB Output is correct
94 Correct 4 ms 3160 KB Output is correct
95 Correct 3 ms 3164 KB Output is correct
96 Correct 3 ms 3160 KB Output is correct
97 Correct 4 ms 3160 KB Output is correct
98 Correct 3 ms 3160 KB Output is correct
99 Correct 3 ms 3160 KB Output is correct
100 Correct 3 ms 3160 KB Output is correct
101 Correct 4 ms 3316 KB Output is correct
102 Correct 3 ms 3164 KB Output is correct
103 Correct 4 ms 3164 KB Output is correct
104 Correct 7 ms 4184 KB Output is correct
105 Correct 12 ms 6744 KB Output is correct
106 Correct 2 ms 3164 KB Output is correct
107 Correct 22 ms 9620 KB Output is correct
108 Correct 32 ms 14296 KB Output is correct
109 Correct 3 ms 3164 KB Output is correct
110 Correct 40 ms 14036 KB Output is correct
111 Correct 58 ms 16592 KB Output is correct
112 Correct 3 ms 3164 KB Output is correct
113 Correct 75 ms 30152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 6232 KB Output is correct
2 Correct 18 ms 6232 KB Output is correct
3 Correct 26 ms 6232 KB Output is correct
4 Correct 23 ms 6236 KB Output is correct
5 Correct 17 ms 6232 KB Output is correct
6 Correct 18 ms 6488 KB Output is correct
7 Correct 20 ms 6492 KB Output is correct
8 Correct 19 ms 6232 KB Output is correct
9 Correct 17 ms 6232 KB Output is correct
10 Correct 23 ms 6612 KB Output is correct
11 Correct 3 ms 3160 KB Output is correct
12 Correct 10 ms 4088 KB Output is correct
13 Correct 7 ms 3928 KB Output is correct
14 Correct 9 ms 4184 KB Output is correct
15 Correct 10 ms 4004 KB Output is correct
16 Correct 10 ms 3672 KB Output is correct
17 Correct 6 ms 3672 KB Output is correct
18 Correct 11 ms 3928 KB Output is correct
19 Correct 7 ms 3928 KB Output is correct
20 Correct 1 ms 3160 KB Output is correct
21 Correct 1 ms 3160 KB Output is correct
22 Correct 4 ms 3164 KB Output is correct
23 Correct 7 ms 3672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3160 KB Output is correct
2 Correct 3 ms 3160 KB Output is correct
3 Correct 2 ms 3164 KB Output is correct
4 Correct 3 ms 3160 KB Output is correct
5 Correct 3 ms 3160 KB Output is correct
6 Correct 3 ms 3160 KB Output is correct
7 Correct 2 ms 3164 KB Output is correct
8 Correct 3 ms 3164 KB Output is correct
9 Correct 4 ms 3164 KB Output is correct
10 Correct 3 ms 3164 KB Output is correct
11 Correct 3 ms 3160 KB Output is correct
12 Correct 4 ms 3216 KB Output is correct
13 Correct 3 ms 3160 KB Output is correct
14 Correct 3 ms 3164 KB Output is correct
15 Correct 2 ms 3416 KB Output is correct
16 Correct 3 ms 3416 KB Output is correct
17 Correct 3 ms 3160 KB Output is correct
18 Correct 3 ms 3160 KB Output is correct
19 Correct 3 ms 3160 KB Output is correct
20 Correct 3 ms 3160 KB Output is correct
21 Correct 4 ms 3164 KB Output is correct
22 Correct 3 ms 3160 KB Output is correct
23 Correct 3 ms 3160 KB Output is correct
24 Correct 3 ms 3164 KB Output is correct
25 Correct 3 ms 3160 KB Output is correct
26 Correct 3 ms 3160 KB Output is correct
27 Correct 3 ms 3160 KB Output is correct
28 Correct 4 ms 3160 KB Output is correct
29 Correct 3 ms 3160 KB Output is correct
30 Correct 3 ms 3160 KB Output is correct
31 Correct 3 ms 3416 KB Output is correct
32 Correct 4 ms 3160 KB Output is correct
33 Correct 3 ms 3160 KB Output is correct
34 Correct 4 ms 3416 KB Output is correct
35 Correct 3 ms 3160 KB Output is correct
36 Correct 2 ms 3160 KB Output is correct
37 Correct 3 ms 3160 KB Output is correct
38 Correct 3 ms 3160 KB Output is correct
39 Correct 3 ms 3160 KB Output is correct
40 Correct 3 ms 3160 KB Output is correct
41 Correct 3 ms 3164 KB Output is correct
42 Correct 3 ms 3416 KB Output is correct
43 Correct 3 ms 3160 KB Output is correct
44 Correct 3 ms 3160 KB Output is correct
45 Correct 3 ms 3160 KB Output is correct
46 Correct 3 ms 3160 KB Output is correct
47 Correct 3 ms 3160 KB Output is correct
48 Correct 3 ms 3160 KB Output is correct
49 Correct 3 ms 3164 KB Output is correct
50 Correct 3 ms 3160 KB Output is correct
51 Correct 3 ms 3164 KB Output is correct
52 Correct 1 ms 3160 KB Output is correct
53 Correct 1 ms 3160 KB Output is correct
54 Incorrect 3 ms 3672 KB Output isn't correct
55 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 19152 KB Output is correct
2 Correct 44 ms 18376 KB Output is correct
3 Correct 36 ms 17612 KB Output is correct
4 Correct 8 ms 5464 KB Output is correct
5 Correct 7 ms 4188 KB Output is correct
6 Correct 13 ms 6904 KB Output is correct
7 Correct 3 ms 3160 KB Output is correct
8 Correct 22 ms 9616 KB Output is correct
9 Correct 34 ms 14292 KB Output is correct
10 Correct 3 ms 3160 KB Output is correct
11 Correct 45 ms 14268 KB Output is correct
12 Correct 42 ms 16592 KB Output is correct
13 Correct 3 ms 3164 KB Output is correct
14 Correct 4 ms 3160 KB Output is correct
15 Correct 3 ms 3160 KB Output is correct
16 Correct 2 ms 3164 KB Output is correct
17 Correct 3 ms 3160 KB Output is correct
18 Correct 3 ms 3160 KB Output is correct
19 Correct 3 ms 3160 KB Output is correct
20 Correct 2 ms 3164 KB Output is correct
21 Correct 3 ms 3164 KB Output is correct
22 Correct 4 ms 3164 KB Output is correct
23 Correct 3 ms 3164 KB Output is correct
24 Correct 3 ms 3160 KB Output is correct
25 Correct 4 ms 3216 KB Output is correct
26 Correct 3 ms 3160 KB Output is correct
27 Correct 3 ms 3164 KB Output is correct
28 Correct 2 ms 3416 KB Output is correct
29 Correct 3 ms 3416 KB Output is correct
30 Correct 3 ms 3160 KB Output is correct
31 Correct 3 ms 3160 KB Output is correct
32 Correct 3 ms 3160 KB Output is correct
33 Correct 3 ms 3160 KB Output is correct
34 Correct 4 ms 3164 KB Output is correct
35 Correct 3 ms 3160 KB Output is correct
36 Correct 3 ms 3160 KB Output is correct
37 Correct 3 ms 3164 KB Output is correct
38 Correct 3 ms 3160 KB Output is correct
39 Correct 54 ms 19152 KB Output is correct
40 Correct 55 ms 18308 KB Output is correct
41 Correct 43 ms 17612 KB Output is correct
42 Correct 8 ms 5464 KB Output is correct
43 Correct 3 ms 3160 KB Output is correct
44 Correct 3 ms 3416 KB Output is correct
45 Correct 3 ms 3160 KB Output is correct
46 Correct 3 ms 3164 KB Output is correct
47 Correct 4 ms 3160 KB Output is correct
48 Correct 3 ms 3420 KB Output is correct
49 Correct 3 ms 3160 KB Output is correct
50 Correct 3 ms 3164 KB Output is correct
51 Correct 3 ms 3160 KB Output is correct
52 Correct 2 ms 3160 KB Output is correct
53 Correct 3 ms 3160 KB Output is correct
54 Correct 3 ms 3164 KB Output is correct
55 Correct 3 ms 3160 KB Output is correct
56 Correct 3 ms 3160 KB Output is correct
57 Correct 49 ms 9672 KB Output is correct
58 Correct 60 ms 9424 KB Output is correct
59 Correct 57 ms 9672 KB Output is correct
60 Correct 47 ms 9512 KB Output is correct
61 Correct 53 ms 9420 KB Output is correct
62 Correct 46 ms 9304 KB Output is correct
63 Correct 43 ms 9392 KB Output is correct
64 Correct 42 ms 9424 KB Output is correct
65 Correct 45 ms 9424 KB Output is correct
66 Correct 43 ms 9168 KB Output is correct
67 Correct 59 ms 9676 KB Output is correct
68 Correct 54 ms 9672 KB Output is correct
69 Correct 54 ms 9420 KB Output is correct
70 Correct 48 ms 9512 KB Output is correct
71 Correct 2 ms 3160 KB Output is correct
72 Correct 4 ms 3416 KB Output is correct
73 Correct 5 ms 3416 KB Output is correct
74 Correct 4 ms 3416 KB Output is correct
75 Correct 4 ms 3160 KB Output is correct
76 Correct 4 ms 3208 KB Output is correct
77 Correct 4 ms 3420 KB Output is correct
78 Correct 4 ms 3420 KB Output is correct
79 Correct 5 ms 3416 KB Output is correct
80 Correct 57 ms 9680 KB Output is correct
81 Correct 45 ms 9428 KB Output is correct
82 Correct 50 ms 9424 KB Output is correct
83 Correct 47 ms 9416 KB Output is correct
84 Correct 3 ms 3160 KB Output is correct
85 Correct 5 ms 3416 KB Output is correct
86 Correct 3 ms 3160 KB Output is correct
87 Correct 4 ms 3160 KB Output is correct
88 Correct 4 ms 3164 KB Output is correct
89 Correct 5 ms 3416 KB Output is correct
90 Correct 4 ms 3164 KB Output is correct
91 Correct 6 ms 3160 KB Output is correct
92 Correct 4 ms 3160 KB Output is correct
93 Correct 5 ms 3160 KB Output is correct
94 Correct 4 ms 3160 KB Output is correct
95 Correct 3 ms 3164 KB Output is correct
96 Correct 3 ms 3160 KB Output is correct
97 Correct 4 ms 3160 KB Output is correct
98 Correct 3 ms 3160 KB Output is correct
99 Correct 3 ms 3160 KB Output is correct
100 Correct 3 ms 3160 KB Output is correct
101 Correct 4 ms 3316 KB Output is correct
102 Correct 3 ms 3164 KB Output is correct
103 Correct 4 ms 3164 KB Output is correct
104 Correct 7 ms 4184 KB Output is correct
105 Correct 12 ms 6744 KB Output is correct
106 Correct 2 ms 3164 KB Output is correct
107 Correct 22 ms 9620 KB Output is correct
108 Correct 32 ms 14296 KB Output is correct
109 Correct 3 ms 3164 KB Output is correct
110 Correct 40 ms 14036 KB Output is correct
111 Correct 58 ms 16592 KB Output is correct
112 Correct 3 ms 3164 KB Output is correct
113 Correct 75 ms 30152 KB Output is correct
114 Correct 20 ms 6232 KB Output is correct
115 Correct 18 ms 6232 KB Output is correct
116 Correct 26 ms 6232 KB Output is correct
117 Correct 23 ms 6236 KB Output is correct
118 Correct 17 ms 6232 KB Output is correct
119 Correct 18 ms 6488 KB Output is correct
120 Correct 20 ms 6492 KB Output is correct
121 Correct 19 ms 6232 KB Output is correct
122 Correct 17 ms 6232 KB Output is correct
123 Correct 23 ms 6612 KB Output is correct
124 Correct 3 ms 3160 KB Output is correct
125 Correct 10 ms 4088 KB Output is correct
126 Correct 7 ms 3928 KB Output is correct
127 Correct 9 ms 4184 KB Output is correct
128 Correct 10 ms 4004 KB Output is correct
129 Correct 10 ms 3672 KB Output is correct
130 Correct 6 ms 3672 KB Output is correct
131 Correct 11 ms 3928 KB Output is correct
132 Correct 7 ms 3928 KB Output is correct
133 Correct 1 ms 3160 KB Output is correct
134 Correct 1 ms 3160 KB Output is correct
135 Correct 4 ms 3164 KB Output is correct
136 Correct 7 ms 3672 KB Output is correct
137 Correct 3 ms 3160 KB Output is correct
138 Correct 3 ms 3160 KB Output is correct
139 Correct 4 ms 3160 KB Output is correct
140 Correct 3 ms 3160 KB Output is correct
141 Correct 3 ms 3160 KB Output is correct
142 Correct 3 ms 3416 KB Output is correct
143 Correct 4 ms 3160 KB Output is correct
144 Correct 3 ms 3160 KB Output is correct
145 Correct 4 ms 3416 KB Output is correct
146 Correct 3 ms 3160 KB Output is correct
147 Correct 2 ms 3160 KB Output is correct
148 Correct 3 ms 3160 KB Output is correct
149 Correct 3 ms 3160 KB Output is correct
150 Correct 3 ms 3160 KB Output is correct
151 Correct 3 ms 3160 KB Output is correct
152 Correct 3 ms 3164 KB Output is correct
153 Correct 3 ms 3416 KB Output is correct
154 Correct 3 ms 3160 KB Output is correct
155 Correct 3 ms 3160 KB Output is correct
156 Correct 3 ms 3160 KB Output is correct
157 Correct 3 ms 3160 KB Output is correct
158 Correct 3 ms 3160 KB Output is correct
159 Correct 3 ms 3160 KB Output is correct
160 Correct 3 ms 3164 KB Output is correct
161 Correct 3 ms 3160 KB Output is correct
162 Correct 3 ms 3164 KB Output is correct
163 Correct 1 ms 3160 KB Output is correct
164 Correct 1 ms 3160 KB Output is correct
165 Incorrect 3 ms 3672 KB Output isn't correct
166 Halted 0 ms 0 KB -