#include "dreaming.h"
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <string>
#include <cassert>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define INF 1005141919
#define _1 first
#define _2 second
int N, L;
vector<P> G[100000];
bool used[100000];
int dp1[100000], dp2[100000], src[100000];
inline void update(int x, int v, int s) {
if (v > dp1[x]) dp2[x] = dp1[x], dp1[x] = v, src[x] = s;
else if (v > dp2[x]) dp2[x] = v;
}
void dfs(int x, int p) {
used[x] = true;
dp1[x] = dp2[x] = 0;
src[x] = -1;
for (P pp : G[x]) if (pp._1 != p) {
int t = pp._1, len = pp._2;
dfs(t, x);
update(x, dp1[t]+len, t);
}
}
int diameter = 0;
int dfs2(int x, int p, int plen) {
if (p != -1) {
int v = dp1[p];
if (src[p] == x) v = dp2[p];
update(x, v+plen, p);
}
diameter = max(diameter, dp1[x]+dp2[x]);
int m = dp1[x];
for (P pp : G[x]) if (pp._1 != p) {
int t = pp._1, len = pp._2;
m = min(m, dfs2(t, x, len));
}
return m;
}
bool f(int X, vector<int> &R) {
int cur_r = R[0];
for (int i=1; i<R.size(); i++) {
int r = R[i];
if (cur_r+r+L > X) return false;
cur_r = min(max(cur_r, r+L), max(cur_r+L, r));
}
return true;
}
int travelTime(int N_, int M, int L_, int A[], int B[], int T[]) {
N = N_, L = L_;
rep(i, M) {
G[A[i]].pb(P(B[i], T[i]));
G[B[i]].pb(P(A[i], T[i]));
}
vector<int> X;
rep(i, N) if (!used[i]) {
dfs(i, -1);
X.pb(dfs2(i, -1, -1));
}
//cout<<"{";for(int x:X)cout<<x<<",";cout<<"}\n";
int lo = diameter-1, hi = INF;
while (hi-lo > 1) {
int mid = (lo+hi)/2;
if (f(mid, X)) hi = mid;
else lo = mid;
}
return hi;
}
Compilation message
dreaming.cpp: In function 'bool f(int, std::vector<int>&)':
dreaming.cpp:55:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=1; i<R.size(); i++) {
~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
11880 KB |
Output is correct |
2 |
Correct |
67 ms |
11384 KB |
Output is correct |
3 |
Correct |
46 ms |
9976 KB |
Output is correct |
4 |
Correct |
11 ms |
3968 KB |
Output is correct |
5 |
Correct |
10 ms |
3456 KB |
Output is correct |
6 |
Correct |
16 ms |
4736 KB |
Output is correct |
7 |
Correct |
4 ms |
2688 KB |
Output is correct |
8 |
Correct |
29 ms |
6520 KB |
Output is correct |
9 |
Correct |
36 ms |
8568 KB |
Output is correct |
10 |
Correct |
4 ms |
2816 KB |
Output is correct |
11 |
Correct |
54 ms |
9208 KB |
Output is correct |
12 |
Correct |
70 ms |
10488 KB |
Output is correct |
13 |
Correct |
4 ms |
2816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
11880 KB |
Output is correct |
2 |
Correct |
67 ms |
11384 KB |
Output is correct |
3 |
Correct |
46 ms |
9976 KB |
Output is correct |
4 |
Correct |
11 ms |
3968 KB |
Output is correct |
5 |
Correct |
10 ms |
3456 KB |
Output is correct |
6 |
Correct |
16 ms |
4736 KB |
Output is correct |
7 |
Correct |
4 ms |
2688 KB |
Output is correct |
8 |
Correct |
29 ms |
6520 KB |
Output is correct |
9 |
Correct |
36 ms |
8568 KB |
Output is correct |
10 |
Correct |
4 ms |
2816 KB |
Output is correct |
11 |
Correct |
54 ms |
9208 KB |
Output is correct |
12 |
Correct |
70 ms |
10488 KB |
Output is correct |
13 |
Correct |
4 ms |
2816 KB |
Output is correct |
14 |
Correct |
4 ms |
2688 KB |
Output is correct |
15 |
Correct |
4 ms |
2688 KB |
Output is correct |
16 |
Correct |
4 ms |
2688 KB |
Output is correct |
17 |
Correct |
4 ms |
2688 KB |
Output is correct |
18 |
Correct |
4 ms |
2688 KB |
Output is correct |
19 |
Correct |
5 ms |
2688 KB |
Output is correct |
20 |
Correct |
4 ms |
2688 KB |
Output is correct |
21 |
Correct |
4 ms |
2688 KB |
Output is correct |
22 |
Correct |
4 ms |
2688 KB |
Output is correct |
23 |
Correct |
4 ms |
2688 KB |
Output is correct |
24 |
Correct |
5 ms |
2688 KB |
Output is correct |
25 |
Correct |
4 ms |
2688 KB |
Output is correct |
26 |
Correct |
4 ms |
2688 KB |
Output is correct |
27 |
Correct |
4 ms |
2688 KB |
Output is correct |
28 |
Correct |
4 ms |
2688 KB |
Output is correct |
29 |
Correct |
4 ms |
2688 KB |
Output is correct |
30 |
Correct |
4 ms |
2688 KB |
Output is correct |
31 |
Correct |
4 ms |
2688 KB |
Output is correct |
32 |
Correct |
4 ms |
2688 KB |
Output is correct |
33 |
Correct |
4 ms |
2736 KB |
Output is correct |
34 |
Correct |
4 ms |
2688 KB |
Output is correct |
35 |
Correct |
4 ms |
2688 KB |
Output is correct |
36 |
Correct |
4 ms |
2688 KB |
Output is correct |
37 |
Correct |
4 ms |
2688 KB |
Output is correct |
38 |
Correct |
4 ms |
2688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
11880 KB |
Output is correct |
2 |
Correct |
67 ms |
11384 KB |
Output is correct |
3 |
Correct |
46 ms |
9976 KB |
Output is correct |
4 |
Correct |
11 ms |
3968 KB |
Output is correct |
5 |
Correct |
10 ms |
3456 KB |
Output is correct |
6 |
Correct |
16 ms |
4736 KB |
Output is correct |
7 |
Correct |
4 ms |
2688 KB |
Output is correct |
8 |
Correct |
29 ms |
6520 KB |
Output is correct |
9 |
Correct |
36 ms |
8568 KB |
Output is correct |
10 |
Correct |
4 ms |
2816 KB |
Output is correct |
11 |
Correct |
54 ms |
9208 KB |
Output is correct |
12 |
Correct |
70 ms |
10488 KB |
Output is correct |
13 |
Correct |
4 ms |
2816 KB |
Output is correct |
14 |
Correct |
4 ms |
2688 KB |
Output is correct |
15 |
Correct |
4 ms |
2688 KB |
Output is correct |
16 |
Correct |
4 ms |
2688 KB |
Output is correct |
17 |
Correct |
4 ms |
2688 KB |
Output is correct |
18 |
Correct |
4 ms |
2688 KB |
Output is correct |
19 |
Correct |
5 ms |
2688 KB |
Output is correct |
20 |
Correct |
4 ms |
2688 KB |
Output is correct |
21 |
Correct |
4 ms |
2688 KB |
Output is correct |
22 |
Correct |
4 ms |
2688 KB |
Output is correct |
23 |
Correct |
4 ms |
2688 KB |
Output is correct |
24 |
Correct |
5 ms |
2688 KB |
Output is correct |
25 |
Correct |
4 ms |
2688 KB |
Output is correct |
26 |
Correct |
4 ms |
2688 KB |
Output is correct |
27 |
Correct |
4 ms |
2688 KB |
Output is correct |
28 |
Correct |
4 ms |
2688 KB |
Output is correct |
29 |
Correct |
4 ms |
2688 KB |
Output is correct |
30 |
Correct |
4 ms |
2688 KB |
Output is correct |
31 |
Correct |
4 ms |
2688 KB |
Output is correct |
32 |
Correct |
4 ms |
2688 KB |
Output is correct |
33 |
Correct |
4 ms |
2736 KB |
Output is correct |
34 |
Correct |
4 ms |
2688 KB |
Output is correct |
35 |
Correct |
4 ms |
2688 KB |
Output is correct |
36 |
Correct |
4 ms |
2688 KB |
Output is correct |
37 |
Correct |
4 ms |
2688 KB |
Output is correct |
38 |
Correct |
4 ms |
2688 KB |
Output is correct |
39 |
Correct |
58 ms |
11768 KB |
Output is correct |
40 |
Correct |
77 ms |
11456 KB |
Output is correct |
41 |
Correct |
39 ms |
10112 KB |
Output is correct |
42 |
Correct |
10 ms |
3968 KB |
Output is correct |
43 |
Correct |
4 ms |
2688 KB |
Output is correct |
44 |
Correct |
4 ms |
2688 KB |
Output is correct |
45 |
Correct |
4 ms |
2688 KB |
Output is correct |
46 |
Correct |
4 ms |
2688 KB |
Output is correct |
47 |
Correct |
4 ms |
2688 KB |
Output is correct |
48 |
Correct |
4 ms |
2688 KB |
Output is correct |
49 |
Correct |
4 ms |
2688 KB |
Output is correct |
50 |
Correct |
4 ms |
2688 KB |
Output is correct |
51 |
Correct |
4 ms |
2688 KB |
Output is correct |
52 |
Correct |
3 ms |
2688 KB |
Output is correct |
53 |
Correct |
4 ms |
2688 KB |
Output is correct |
54 |
Correct |
4 ms |
2688 KB |
Output is correct |
55 |
Correct |
4 ms |
2688 KB |
Output is correct |
56 |
Correct |
4 ms |
2688 KB |
Output is correct |
57 |
Correct |
79 ms |
9136 KB |
Output is correct |
58 |
Correct |
76 ms |
9080 KB |
Output is correct |
59 |
Correct |
89 ms |
9080 KB |
Output is correct |
60 |
Correct |
89 ms |
8952 KB |
Output is correct |
61 |
Correct |
71 ms |
8948 KB |
Output is correct |
62 |
Correct |
71 ms |
8952 KB |
Output is correct |
63 |
Correct |
68 ms |
8824 KB |
Output is correct |
64 |
Correct |
68 ms |
8796 KB |
Output is correct |
65 |
Correct |
83 ms |
8952 KB |
Output is correct |
66 |
Correct |
81 ms |
8840 KB |
Output is correct |
67 |
Correct |
74 ms |
9080 KB |
Output is correct |
68 |
Correct |
75 ms |
9080 KB |
Output is correct |
69 |
Correct |
100 ms |
9080 KB |
Output is correct |
70 |
Correct |
92 ms |
8952 KB |
Output is correct |
71 |
Correct |
4 ms |
2688 KB |
Output is correct |
72 |
Correct |
5 ms |
2944 KB |
Output is correct |
73 |
Correct |
5 ms |
2944 KB |
Output is correct |
74 |
Correct |
5 ms |
2816 KB |
Output is correct |
75 |
Correct |
5 ms |
2816 KB |
Output is correct |
76 |
Correct |
5 ms |
2944 KB |
Output is correct |
77 |
Correct |
5 ms |
2944 KB |
Output is correct |
78 |
Correct |
5 ms |
2944 KB |
Output is correct |
79 |
Correct |
5 ms |
2944 KB |
Output is correct |
80 |
Correct |
70 ms |
8956 KB |
Output is correct |
81 |
Correct |
83 ms |
9080 KB |
Output is correct |
82 |
Correct |
70 ms |
8900 KB |
Output is correct |
83 |
Correct |
67 ms |
8952 KB |
Output is correct |
84 |
Correct |
5 ms |
2816 KB |
Output is correct |
85 |
Correct |
4 ms |
2816 KB |
Output is correct |
86 |
Correct |
7 ms |
2816 KB |
Output is correct |
87 |
Correct |
5 ms |
2944 KB |
Output is correct |
88 |
Correct |
5 ms |
2944 KB |
Output is correct |
89 |
Correct |
6 ms |
2944 KB |
Output is correct |
90 |
Correct |
6 ms |
2944 KB |
Output is correct |
91 |
Correct |
5 ms |
2816 KB |
Output is correct |
92 |
Correct |
5 ms |
2944 KB |
Output is correct |
93 |
Correct |
5 ms |
2816 KB |
Output is correct |
94 |
Correct |
3 ms |
2688 KB |
Output is correct |
95 |
Correct |
4 ms |
2688 KB |
Output is correct |
96 |
Correct |
4 ms |
2688 KB |
Output is correct |
97 |
Correct |
4 ms |
2688 KB |
Output is correct |
98 |
Correct |
4 ms |
2688 KB |
Output is correct |
99 |
Correct |
4 ms |
2688 KB |
Output is correct |
100 |
Correct |
4 ms |
2688 KB |
Output is correct |
101 |
Correct |
4 ms |
2688 KB |
Output is correct |
102 |
Correct |
4 ms |
2688 KB |
Output is correct |
103 |
Correct |
4 ms |
2688 KB |
Output is correct |
104 |
Correct |
9 ms |
3456 KB |
Output is correct |
105 |
Correct |
16 ms |
4736 KB |
Output is correct |
106 |
Correct |
4 ms |
2688 KB |
Output is correct |
107 |
Correct |
32 ms |
6400 KB |
Output is correct |
108 |
Correct |
37 ms |
8440 KB |
Output is correct |
109 |
Correct |
4 ms |
2816 KB |
Output is correct |
110 |
Correct |
51 ms |
9208 KB |
Output is correct |
111 |
Correct |
60 ms |
10492 KB |
Output is correct |
112 |
Correct |
4 ms |
2816 KB |
Output is correct |
113 |
Correct |
92 ms |
15992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
6528 KB |
Output is correct |
2 |
Incorrect |
34 ms |
6648 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
11880 KB |
Output is correct |
2 |
Correct |
67 ms |
11384 KB |
Output is correct |
3 |
Correct |
46 ms |
9976 KB |
Output is correct |
4 |
Correct |
11 ms |
3968 KB |
Output is correct |
5 |
Correct |
10 ms |
3456 KB |
Output is correct |
6 |
Correct |
16 ms |
4736 KB |
Output is correct |
7 |
Correct |
4 ms |
2688 KB |
Output is correct |
8 |
Correct |
29 ms |
6520 KB |
Output is correct |
9 |
Correct |
36 ms |
8568 KB |
Output is correct |
10 |
Correct |
4 ms |
2816 KB |
Output is correct |
11 |
Correct |
54 ms |
9208 KB |
Output is correct |
12 |
Correct |
70 ms |
10488 KB |
Output is correct |
13 |
Correct |
4 ms |
2816 KB |
Output is correct |
14 |
Correct |
4 ms |
2816 KB |
Output is correct |
15 |
Correct |
7 ms |
2816 KB |
Output is correct |
16 |
Correct |
4 ms |
2944 KB |
Output is correct |
17 |
Correct |
4 ms |
2788 KB |
Output is correct |
18 |
Correct |
5 ms |
2816 KB |
Output is correct |
19 |
Correct |
5 ms |
2816 KB |
Output is correct |
20 |
Correct |
4 ms |
2688 KB |
Output is correct |
21 |
Incorrect |
5 ms |
2860 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
11880 KB |
Output is correct |
2 |
Correct |
67 ms |
11384 KB |
Output is correct |
3 |
Correct |
46 ms |
9976 KB |
Output is correct |
4 |
Correct |
11 ms |
3968 KB |
Output is correct |
5 |
Correct |
10 ms |
3456 KB |
Output is correct |
6 |
Correct |
16 ms |
4736 KB |
Output is correct |
7 |
Correct |
4 ms |
2688 KB |
Output is correct |
8 |
Correct |
29 ms |
6520 KB |
Output is correct |
9 |
Correct |
36 ms |
8568 KB |
Output is correct |
10 |
Correct |
4 ms |
2816 KB |
Output is correct |
11 |
Correct |
54 ms |
9208 KB |
Output is correct |
12 |
Correct |
70 ms |
10488 KB |
Output is correct |
13 |
Correct |
4 ms |
2816 KB |
Output is correct |
14 |
Correct |
4 ms |
2688 KB |
Output is correct |
15 |
Correct |
4 ms |
2688 KB |
Output is correct |
16 |
Correct |
4 ms |
2688 KB |
Output is correct |
17 |
Correct |
4 ms |
2688 KB |
Output is correct |
18 |
Correct |
4 ms |
2688 KB |
Output is correct |
19 |
Correct |
5 ms |
2688 KB |
Output is correct |
20 |
Correct |
4 ms |
2688 KB |
Output is correct |
21 |
Correct |
4 ms |
2688 KB |
Output is correct |
22 |
Correct |
4 ms |
2688 KB |
Output is correct |
23 |
Correct |
4 ms |
2688 KB |
Output is correct |
24 |
Correct |
5 ms |
2688 KB |
Output is correct |
25 |
Correct |
4 ms |
2688 KB |
Output is correct |
26 |
Correct |
4 ms |
2688 KB |
Output is correct |
27 |
Correct |
4 ms |
2688 KB |
Output is correct |
28 |
Correct |
4 ms |
2688 KB |
Output is correct |
29 |
Correct |
4 ms |
2688 KB |
Output is correct |
30 |
Correct |
4 ms |
2688 KB |
Output is correct |
31 |
Correct |
4 ms |
2688 KB |
Output is correct |
32 |
Correct |
4 ms |
2688 KB |
Output is correct |
33 |
Correct |
4 ms |
2736 KB |
Output is correct |
34 |
Correct |
4 ms |
2688 KB |
Output is correct |
35 |
Correct |
4 ms |
2688 KB |
Output is correct |
36 |
Correct |
4 ms |
2688 KB |
Output is correct |
37 |
Correct |
4 ms |
2688 KB |
Output is correct |
38 |
Correct |
4 ms |
2688 KB |
Output is correct |
39 |
Correct |
58 ms |
11768 KB |
Output is correct |
40 |
Correct |
77 ms |
11456 KB |
Output is correct |
41 |
Correct |
39 ms |
10112 KB |
Output is correct |
42 |
Correct |
10 ms |
3968 KB |
Output is correct |
43 |
Correct |
4 ms |
2688 KB |
Output is correct |
44 |
Correct |
4 ms |
2688 KB |
Output is correct |
45 |
Correct |
4 ms |
2688 KB |
Output is correct |
46 |
Correct |
4 ms |
2688 KB |
Output is correct |
47 |
Correct |
4 ms |
2688 KB |
Output is correct |
48 |
Correct |
4 ms |
2688 KB |
Output is correct |
49 |
Correct |
4 ms |
2688 KB |
Output is correct |
50 |
Correct |
4 ms |
2688 KB |
Output is correct |
51 |
Correct |
4 ms |
2688 KB |
Output is correct |
52 |
Correct |
3 ms |
2688 KB |
Output is correct |
53 |
Correct |
4 ms |
2688 KB |
Output is correct |
54 |
Correct |
4 ms |
2688 KB |
Output is correct |
55 |
Correct |
4 ms |
2688 KB |
Output is correct |
56 |
Correct |
4 ms |
2688 KB |
Output is correct |
57 |
Correct |
79 ms |
9136 KB |
Output is correct |
58 |
Correct |
76 ms |
9080 KB |
Output is correct |
59 |
Correct |
89 ms |
9080 KB |
Output is correct |
60 |
Correct |
89 ms |
8952 KB |
Output is correct |
61 |
Correct |
71 ms |
8948 KB |
Output is correct |
62 |
Correct |
71 ms |
8952 KB |
Output is correct |
63 |
Correct |
68 ms |
8824 KB |
Output is correct |
64 |
Correct |
68 ms |
8796 KB |
Output is correct |
65 |
Correct |
83 ms |
8952 KB |
Output is correct |
66 |
Correct |
81 ms |
8840 KB |
Output is correct |
67 |
Correct |
74 ms |
9080 KB |
Output is correct |
68 |
Correct |
75 ms |
9080 KB |
Output is correct |
69 |
Correct |
100 ms |
9080 KB |
Output is correct |
70 |
Correct |
92 ms |
8952 KB |
Output is correct |
71 |
Correct |
4 ms |
2688 KB |
Output is correct |
72 |
Correct |
5 ms |
2944 KB |
Output is correct |
73 |
Correct |
5 ms |
2944 KB |
Output is correct |
74 |
Correct |
5 ms |
2816 KB |
Output is correct |
75 |
Correct |
5 ms |
2816 KB |
Output is correct |
76 |
Correct |
5 ms |
2944 KB |
Output is correct |
77 |
Correct |
5 ms |
2944 KB |
Output is correct |
78 |
Correct |
5 ms |
2944 KB |
Output is correct |
79 |
Correct |
5 ms |
2944 KB |
Output is correct |
80 |
Correct |
70 ms |
8956 KB |
Output is correct |
81 |
Correct |
83 ms |
9080 KB |
Output is correct |
82 |
Correct |
70 ms |
8900 KB |
Output is correct |
83 |
Correct |
67 ms |
8952 KB |
Output is correct |
84 |
Correct |
5 ms |
2816 KB |
Output is correct |
85 |
Correct |
4 ms |
2816 KB |
Output is correct |
86 |
Correct |
7 ms |
2816 KB |
Output is correct |
87 |
Correct |
5 ms |
2944 KB |
Output is correct |
88 |
Correct |
5 ms |
2944 KB |
Output is correct |
89 |
Correct |
6 ms |
2944 KB |
Output is correct |
90 |
Correct |
6 ms |
2944 KB |
Output is correct |
91 |
Correct |
5 ms |
2816 KB |
Output is correct |
92 |
Correct |
5 ms |
2944 KB |
Output is correct |
93 |
Correct |
5 ms |
2816 KB |
Output is correct |
94 |
Correct |
3 ms |
2688 KB |
Output is correct |
95 |
Correct |
4 ms |
2688 KB |
Output is correct |
96 |
Correct |
4 ms |
2688 KB |
Output is correct |
97 |
Correct |
4 ms |
2688 KB |
Output is correct |
98 |
Correct |
4 ms |
2688 KB |
Output is correct |
99 |
Correct |
4 ms |
2688 KB |
Output is correct |
100 |
Correct |
4 ms |
2688 KB |
Output is correct |
101 |
Correct |
4 ms |
2688 KB |
Output is correct |
102 |
Correct |
4 ms |
2688 KB |
Output is correct |
103 |
Correct |
4 ms |
2688 KB |
Output is correct |
104 |
Correct |
9 ms |
3456 KB |
Output is correct |
105 |
Correct |
16 ms |
4736 KB |
Output is correct |
106 |
Correct |
4 ms |
2688 KB |
Output is correct |
107 |
Correct |
32 ms |
6400 KB |
Output is correct |
108 |
Correct |
37 ms |
8440 KB |
Output is correct |
109 |
Correct |
4 ms |
2816 KB |
Output is correct |
110 |
Correct |
51 ms |
9208 KB |
Output is correct |
111 |
Correct |
60 ms |
10492 KB |
Output is correct |
112 |
Correct |
4 ms |
2816 KB |
Output is correct |
113 |
Correct |
92 ms |
15992 KB |
Output is correct |
114 |
Correct |
28 ms |
6528 KB |
Output is correct |
115 |
Incorrect |
34 ms |
6648 KB |
Output isn't correct |
116 |
Halted |
0 ms |
0 KB |
- |