#include "dreaming.h"
#include <bits/stdc++.h>
#define endl "\n"
#define F first
#define S second
#define pb push_back
typedef long long ll;
using namespace std;
const int N = 1e5+5;
const long long oo = 1e18 ;
vector <pair <ll,ll>> v[N] ;
ll n , m , ans , best , mx , dis[N] , len ;
bool vis[N] ;
pair <ll,ll> dfs (ll u , ll p)
{
vis[u] = true ;
pair <ll,ll> ret = {0 , u} ;
for (auto it : v[u])
{
if (it.F == p) continue ;
pair <ll,ll> p = dfs(it.F , u) ;
p.F += it.S ;
ret = max(ret , p) ;
}
best = min(best , max(len - ret.F , ret.F) ) ;
return ret ;
}
ll get (ll p)
{
ll p1 , p2 ;
p1 = dfs(p , p).S ;
p2 = dfs(p1 , p1).S ;
len = dfs(p1 , p1).F ;
best = oo ;
dfs(p1 , p1) ;
return best ;
}
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++)
{
v[B[i]].pb({A[i] , T[i]});
v[A[i]].pb({B[i] , T[i]});
}
ans += get(1) ;
ll bans = len ;
for (int i = 1 ; i<=n ; i++)
{
if (!vis[i])
{
ans += get(i) ;
break ;
}
}
bans = max(bans , len) ;
return max(bans , ans + L) ;
}
Compilation message
dreaming.cpp: In function 'll get(ll)':
dreaming.cpp:53:13: warning: variable 'p2' set but not used [-Wunused-but-set-variable]
53 | ll p1 , p2 ;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
15180 KB |
Output is correct |
2 |
Correct |
61 ms |
16392 KB |
Output is correct |
3 |
Correct |
40 ms |
11800 KB |
Output is correct |
4 |
Correct |
9 ms |
4708 KB |
Output is correct |
5 |
Correct |
9 ms |
3796 KB |
Output is correct |
6 |
Correct |
14 ms |
5872 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
26 ms |
7608 KB |
Output is correct |
9 |
Correct |
44 ms |
9704 KB |
Output is correct |
10 |
Correct |
2 ms |
2660 KB |
Output is correct |
11 |
Correct |
55 ms |
11980 KB |
Output is correct |
12 |
Correct |
102 ms |
14316 KB |
Output is correct |
13 |
Correct |
3 ms |
2772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2660 KB |
Output is correct |
5 |
Correct |
2 ms |
2660 KB |
Output is correct |
6 |
Correct |
2 ms |
2660 KB |
Output is correct |
7 |
Correct |
2 ms |
2660 KB |
Output is correct |
8 |
Correct |
2 ms |
2668 KB |
Output is correct |
9 |
Correct |
2 ms |
2580 KB |
Output is correct |
10 |
Correct |
2 ms |
2656 KB |
Output is correct |
11 |
Correct |
2 ms |
2644 KB |
Output is correct |
12 |
Correct |
2 ms |
2644 KB |
Output is correct |
13 |
Correct |
2 ms |
2644 KB |
Output is correct |
14 |
Correct |
2 ms |
2656 KB |
Output is correct |
15 |
Correct |
2 ms |
2644 KB |
Output is correct |
16 |
Correct |
2 ms |
2644 KB |
Output is correct |
17 |
Correct |
2 ms |
2660 KB |
Output is correct |
18 |
Correct |
2 ms |
2656 KB |
Output is correct |
19 |
Correct |
2 ms |
2664 KB |
Output is correct |
20 |
Correct |
2 ms |
2644 KB |
Output is correct |
21 |
Correct |
1 ms |
2664 KB |
Output is correct |
22 |
Correct |
2 ms |
2644 KB |
Output is correct |
23 |
Correct |
2 ms |
2644 KB |
Output is correct |
24 |
Correct |
2 ms |
2660 KB |
Output is correct |
25 |
Correct |
3 ms |
2660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
15180 KB |
Output is correct |
2 |
Correct |
61 ms |
16392 KB |
Output is correct |
3 |
Correct |
40 ms |
11800 KB |
Output is correct |
4 |
Correct |
9 ms |
4708 KB |
Output is correct |
5 |
Correct |
9 ms |
3796 KB |
Output is correct |
6 |
Correct |
14 ms |
5872 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
26 ms |
7608 KB |
Output is correct |
9 |
Correct |
44 ms |
9704 KB |
Output is correct |
10 |
Correct |
2 ms |
2660 KB |
Output is correct |
11 |
Correct |
55 ms |
11980 KB |
Output is correct |
12 |
Correct |
102 ms |
14316 KB |
Output is correct |
13 |
Correct |
3 ms |
2772 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
2 ms |
2644 KB |
Output is correct |
16 |
Correct |
2 ms |
2644 KB |
Output is correct |
17 |
Correct |
2 ms |
2660 KB |
Output is correct |
18 |
Correct |
2 ms |
2660 KB |
Output is correct |
19 |
Correct |
2 ms |
2660 KB |
Output is correct |
20 |
Correct |
2 ms |
2660 KB |
Output is correct |
21 |
Correct |
2 ms |
2668 KB |
Output is correct |
22 |
Correct |
2 ms |
2580 KB |
Output is correct |
23 |
Correct |
2 ms |
2656 KB |
Output is correct |
24 |
Correct |
2 ms |
2644 KB |
Output is correct |
25 |
Correct |
2 ms |
2644 KB |
Output is correct |
26 |
Correct |
2 ms |
2644 KB |
Output is correct |
27 |
Correct |
2 ms |
2656 KB |
Output is correct |
28 |
Correct |
2 ms |
2644 KB |
Output is correct |
29 |
Correct |
2 ms |
2644 KB |
Output is correct |
30 |
Correct |
2 ms |
2660 KB |
Output is correct |
31 |
Correct |
2 ms |
2656 KB |
Output is correct |
32 |
Correct |
2 ms |
2664 KB |
Output is correct |
33 |
Correct |
2 ms |
2644 KB |
Output is correct |
34 |
Correct |
1 ms |
2664 KB |
Output is correct |
35 |
Correct |
2 ms |
2644 KB |
Output is correct |
36 |
Correct |
2 ms |
2644 KB |
Output is correct |
37 |
Correct |
2 ms |
2660 KB |
Output is correct |
38 |
Correct |
3 ms |
2660 KB |
Output is correct |
39 |
Correct |
64 ms |
16396 KB |
Output is correct |
40 |
Correct |
74 ms |
16332 KB |
Output is correct |
41 |
Correct |
32 ms |
11740 KB |
Output is correct |
42 |
Correct |
8 ms |
4608 KB |
Output is correct |
43 |
Correct |
2 ms |
2660 KB |
Output is correct |
44 |
Correct |
1 ms |
2644 KB |
Output is correct |
45 |
Correct |
2 ms |
2644 KB |
Output is correct |
46 |
Correct |
2 ms |
2644 KB |
Output is correct |
47 |
Correct |
2 ms |
2644 KB |
Output is correct |
48 |
Correct |
2 ms |
2644 KB |
Output is correct |
49 |
Correct |
2 ms |
2644 KB |
Output is correct |
50 |
Correct |
2 ms |
2644 KB |
Output is correct |
51 |
Correct |
2 ms |
2644 KB |
Output is correct |
52 |
Correct |
2 ms |
2644 KB |
Output is correct |
53 |
Correct |
2 ms |
2644 KB |
Output is correct |
54 |
Correct |
2 ms |
2660 KB |
Output is correct |
55 |
Correct |
2 ms |
2644 KB |
Output is correct |
56 |
Correct |
2 ms |
2664 KB |
Output is correct |
57 |
Correct |
82 ms |
11148 KB |
Output is correct |
58 |
Correct |
78 ms |
11108 KB |
Output is correct |
59 |
Correct |
89 ms |
10808 KB |
Output is correct |
60 |
Correct |
111 ms |
10924 KB |
Output is correct |
61 |
Correct |
90 ms |
10756 KB |
Output is correct |
62 |
Correct |
101 ms |
10868 KB |
Output is correct |
63 |
Correct |
127 ms |
10420 KB |
Output is correct |
64 |
Correct |
70 ms |
10316 KB |
Output is correct |
65 |
Correct |
70 ms |
10692 KB |
Output is correct |
66 |
Correct |
74 ms |
10652 KB |
Output is correct |
67 |
Correct |
80 ms |
10816 KB |
Output is correct |
68 |
Correct |
101 ms |
10848 KB |
Output is correct |
69 |
Correct |
109 ms |
11220 KB |
Output is correct |
70 |
Correct |
103 ms |
11180 KB |
Output is correct |
71 |
Correct |
2 ms |
2656 KB |
Output is correct |
72 |
Correct |
4 ms |
2936 KB |
Output is correct |
73 |
Correct |
4 ms |
2932 KB |
Output is correct |
74 |
Correct |
4 ms |
2840 KB |
Output is correct |
75 |
Correct |
4 ms |
2836 KB |
Output is correct |
76 |
Correct |
4 ms |
2928 KB |
Output is correct |
77 |
Correct |
3 ms |
2900 KB |
Output is correct |
78 |
Correct |
4 ms |
2868 KB |
Output is correct |
79 |
Correct |
3 ms |
2928 KB |
Output is correct |
80 |
Correct |
87 ms |
10860 KB |
Output is correct |
81 |
Correct |
96 ms |
10796 KB |
Output is correct |
82 |
Correct |
89 ms |
10852 KB |
Output is correct |
83 |
Correct |
76 ms |
10868 KB |
Output is correct |
84 |
Correct |
3 ms |
2772 KB |
Output is correct |
85 |
Correct |
2 ms |
2772 KB |
Output is correct |
86 |
Correct |
3 ms |
2772 KB |
Output is correct |
87 |
Correct |
3 ms |
2796 KB |
Output is correct |
88 |
Correct |
3 ms |
2772 KB |
Output is correct |
89 |
Correct |
3 ms |
2796 KB |
Output is correct |
90 |
Correct |
3 ms |
2772 KB |
Output is correct |
91 |
Correct |
3 ms |
2900 KB |
Output is correct |
92 |
Correct |
4 ms |
2772 KB |
Output is correct |
93 |
Correct |
4 ms |
2772 KB |
Output is correct |
94 |
Correct |
2 ms |
2656 KB |
Output is correct |
95 |
Correct |
2 ms |
2644 KB |
Output is correct |
96 |
Correct |
2 ms |
2656 KB |
Output is correct |
97 |
Correct |
2 ms |
2644 KB |
Output is correct |
98 |
Correct |
2 ms |
2644 KB |
Output is correct |
99 |
Correct |
2 ms |
2644 KB |
Output is correct |
100 |
Correct |
2 ms |
2644 KB |
Output is correct |
101 |
Correct |
2 ms |
2656 KB |
Output is correct |
102 |
Correct |
3 ms |
2644 KB |
Output is correct |
103 |
Correct |
2 ms |
2688 KB |
Output is correct |
104 |
Correct |
8 ms |
3820 KB |
Output is correct |
105 |
Correct |
19 ms |
5792 KB |
Output is correct |
106 |
Correct |
2 ms |
2660 KB |
Output is correct |
107 |
Correct |
40 ms |
7676 KB |
Output is correct |
108 |
Correct |
49 ms |
9732 KB |
Output is correct |
109 |
Correct |
2 ms |
2664 KB |
Output is correct |
110 |
Correct |
59 ms |
11964 KB |
Output is correct |
111 |
Correct |
94 ms |
14308 KB |
Output is correct |
112 |
Correct |
2 ms |
2796 KB |
Output is correct |
113 |
Correct |
114 ms |
18568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
15 ms |
4968 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2660 KB |
Output is correct |
5 |
Correct |
2 ms |
2660 KB |
Output is correct |
6 |
Correct |
2 ms |
2660 KB |
Output is correct |
7 |
Correct |
2 ms |
2660 KB |
Output is correct |
8 |
Correct |
2 ms |
2668 KB |
Output is correct |
9 |
Correct |
2 ms |
2580 KB |
Output is correct |
10 |
Correct |
2 ms |
2656 KB |
Output is correct |
11 |
Correct |
2 ms |
2644 KB |
Output is correct |
12 |
Correct |
2 ms |
2644 KB |
Output is correct |
13 |
Correct |
2 ms |
2644 KB |
Output is correct |
14 |
Correct |
2 ms |
2656 KB |
Output is correct |
15 |
Correct |
2 ms |
2644 KB |
Output is correct |
16 |
Correct |
2 ms |
2644 KB |
Output is correct |
17 |
Correct |
2 ms |
2660 KB |
Output is correct |
18 |
Correct |
2 ms |
2656 KB |
Output is correct |
19 |
Correct |
2 ms |
2664 KB |
Output is correct |
20 |
Correct |
2 ms |
2644 KB |
Output is correct |
21 |
Correct |
1 ms |
2664 KB |
Output is correct |
22 |
Correct |
2 ms |
2644 KB |
Output is correct |
23 |
Correct |
2 ms |
2644 KB |
Output is correct |
24 |
Correct |
2 ms |
2660 KB |
Output is correct |
25 |
Correct |
3 ms |
2660 KB |
Output is correct |
26 |
Correct |
2 ms |
2644 KB |
Output is correct |
27 |
Incorrect |
3 ms |
2772 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
15180 KB |
Output is correct |
2 |
Correct |
61 ms |
16392 KB |
Output is correct |
3 |
Correct |
40 ms |
11800 KB |
Output is correct |
4 |
Correct |
9 ms |
4708 KB |
Output is correct |
5 |
Correct |
9 ms |
3796 KB |
Output is correct |
6 |
Correct |
14 ms |
5872 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
26 ms |
7608 KB |
Output is correct |
9 |
Correct |
44 ms |
9704 KB |
Output is correct |
10 |
Correct |
2 ms |
2660 KB |
Output is correct |
11 |
Correct |
55 ms |
11980 KB |
Output is correct |
12 |
Correct |
102 ms |
14316 KB |
Output is correct |
13 |
Correct |
3 ms |
2772 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
2 ms |
2644 KB |
Output is correct |
16 |
Correct |
2 ms |
2644 KB |
Output is correct |
17 |
Correct |
2 ms |
2660 KB |
Output is correct |
18 |
Correct |
2 ms |
2660 KB |
Output is correct |
19 |
Correct |
2 ms |
2660 KB |
Output is correct |
20 |
Correct |
2 ms |
2660 KB |
Output is correct |
21 |
Correct |
2 ms |
2668 KB |
Output is correct |
22 |
Correct |
2 ms |
2580 KB |
Output is correct |
23 |
Correct |
2 ms |
2656 KB |
Output is correct |
24 |
Correct |
2 ms |
2644 KB |
Output is correct |
25 |
Correct |
2 ms |
2644 KB |
Output is correct |
26 |
Correct |
2 ms |
2644 KB |
Output is correct |
27 |
Correct |
2 ms |
2656 KB |
Output is correct |
28 |
Correct |
2 ms |
2644 KB |
Output is correct |
29 |
Correct |
2 ms |
2644 KB |
Output is correct |
30 |
Correct |
2 ms |
2660 KB |
Output is correct |
31 |
Correct |
2 ms |
2656 KB |
Output is correct |
32 |
Correct |
2 ms |
2664 KB |
Output is correct |
33 |
Correct |
2 ms |
2644 KB |
Output is correct |
34 |
Correct |
1 ms |
2664 KB |
Output is correct |
35 |
Correct |
2 ms |
2644 KB |
Output is correct |
36 |
Correct |
2 ms |
2644 KB |
Output is correct |
37 |
Correct |
2 ms |
2660 KB |
Output is correct |
38 |
Correct |
3 ms |
2660 KB |
Output is correct |
39 |
Correct |
64 ms |
16396 KB |
Output is correct |
40 |
Correct |
74 ms |
16332 KB |
Output is correct |
41 |
Correct |
32 ms |
11740 KB |
Output is correct |
42 |
Correct |
8 ms |
4608 KB |
Output is correct |
43 |
Correct |
2 ms |
2660 KB |
Output is correct |
44 |
Correct |
1 ms |
2644 KB |
Output is correct |
45 |
Correct |
2 ms |
2644 KB |
Output is correct |
46 |
Correct |
2 ms |
2644 KB |
Output is correct |
47 |
Correct |
2 ms |
2644 KB |
Output is correct |
48 |
Correct |
2 ms |
2644 KB |
Output is correct |
49 |
Correct |
2 ms |
2644 KB |
Output is correct |
50 |
Correct |
2 ms |
2644 KB |
Output is correct |
51 |
Correct |
2 ms |
2644 KB |
Output is correct |
52 |
Correct |
2 ms |
2644 KB |
Output is correct |
53 |
Correct |
2 ms |
2644 KB |
Output is correct |
54 |
Correct |
2 ms |
2660 KB |
Output is correct |
55 |
Correct |
2 ms |
2644 KB |
Output is correct |
56 |
Correct |
2 ms |
2664 KB |
Output is correct |
57 |
Correct |
82 ms |
11148 KB |
Output is correct |
58 |
Correct |
78 ms |
11108 KB |
Output is correct |
59 |
Correct |
89 ms |
10808 KB |
Output is correct |
60 |
Correct |
111 ms |
10924 KB |
Output is correct |
61 |
Correct |
90 ms |
10756 KB |
Output is correct |
62 |
Correct |
101 ms |
10868 KB |
Output is correct |
63 |
Correct |
127 ms |
10420 KB |
Output is correct |
64 |
Correct |
70 ms |
10316 KB |
Output is correct |
65 |
Correct |
70 ms |
10692 KB |
Output is correct |
66 |
Correct |
74 ms |
10652 KB |
Output is correct |
67 |
Correct |
80 ms |
10816 KB |
Output is correct |
68 |
Correct |
101 ms |
10848 KB |
Output is correct |
69 |
Correct |
109 ms |
11220 KB |
Output is correct |
70 |
Correct |
103 ms |
11180 KB |
Output is correct |
71 |
Correct |
2 ms |
2656 KB |
Output is correct |
72 |
Correct |
4 ms |
2936 KB |
Output is correct |
73 |
Correct |
4 ms |
2932 KB |
Output is correct |
74 |
Correct |
4 ms |
2840 KB |
Output is correct |
75 |
Correct |
4 ms |
2836 KB |
Output is correct |
76 |
Correct |
4 ms |
2928 KB |
Output is correct |
77 |
Correct |
3 ms |
2900 KB |
Output is correct |
78 |
Correct |
4 ms |
2868 KB |
Output is correct |
79 |
Correct |
3 ms |
2928 KB |
Output is correct |
80 |
Correct |
87 ms |
10860 KB |
Output is correct |
81 |
Correct |
96 ms |
10796 KB |
Output is correct |
82 |
Correct |
89 ms |
10852 KB |
Output is correct |
83 |
Correct |
76 ms |
10868 KB |
Output is correct |
84 |
Correct |
3 ms |
2772 KB |
Output is correct |
85 |
Correct |
2 ms |
2772 KB |
Output is correct |
86 |
Correct |
3 ms |
2772 KB |
Output is correct |
87 |
Correct |
3 ms |
2796 KB |
Output is correct |
88 |
Correct |
3 ms |
2772 KB |
Output is correct |
89 |
Correct |
3 ms |
2796 KB |
Output is correct |
90 |
Correct |
3 ms |
2772 KB |
Output is correct |
91 |
Correct |
3 ms |
2900 KB |
Output is correct |
92 |
Correct |
4 ms |
2772 KB |
Output is correct |
93 |
Correct |
4 ms |
2772 KB |
Output is correct |
94 |
Correct |
2 ms |
2656 KB |
Output is correct |
95 |
Correct |
2 ms |
2644 KB |
Output is correct |
96 |
Correct |
2 ms |
2656 KB |
Output is correct |
97 |
Correct |
2 ms |
2644 KB |
Output is correct |
98 |
Correct |
2 ms |
2644 KB |
Output is correct |
99 |
Correct |
2 ms |
2644 KB |
Output is correct |
100 |
Correct |
2 ms |
2644 KB |
Output is correct |
101 |
Correct |
2 ms |
2656 KB |
Output is correct |
102 |
Correct |
3 ms |
2644 KB |
Output is correct |
103 |
Correct |
2 ms |
2688 KB |
Output is correct |
104 |
Correct |
8 ms |
3820 KB |
Output is correct |
105 |
Correct |
19 ms |
5792 KB |
Output is correct |
106 |
Correct |
2 ms |
2660 KB |
Output is correct |
107 |
Correct |
40 ms |
7676 KB |
Output is correct |
108 |
Correct |
49 ms |
9732 KB |
Output is correct |
109 |
Correct |
2 ms |
2664 KB |
Output is correct |
110 |
Correct |
59 ms |
11964 KB |
Output is correct |
111 |
Correct |
94 ms |
14308 KB |
Output is correct |
112 |
Correct |
2 ms |
2796 KB |
Output is correct |
113 |
Correct |
114 ms |
18568 KB |
Output is correct |
114 |
Incorrect |
15 ms |
4968 KB |
Output isn't correct |
115 |
Halted |
0 ms |
0 KB |
- |