#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 = 1e6+5;
const long long oo = 1e18 ;
vector <pair <ll,ll>> v[N] ;
ll n , m , ans , best , mx , dis[N] , len ;
bool vis[N] ;
void dfs (ll u , ll p , ll cost)
{
dis[u] = cost ;
vis[u] = true ;
for (auto it : v[u])
{
if (it.F != p)
dfs(it.F , u , cost + it.S);
}
}
bool dfs2 (ll u , ll p , ll cost , ll gol)
{
bool is = false ;
for (auto it : v[u])
{
if (it.F != p)
is |= dfs2(it.F , u , cost + it.S , gol) ;
}
is |= (u == gol);
if (is)
best = min (best , max(cost , len-cost));
return is ;
}
ll p1 , p2 ;
ll far (ll p)
{
mx = 0 ; ll ret ;
for (int i = 1 ; i<=n ; i++)
dis[i] = 0 ;
dfs(p , p , 0) ;
for (int i = 1 ; i<=n ; i++)
{
if (dis[i] >= mx)
ret = i , mx = dis[i] ;
dis[i] = 0 ;
}
return ret ;
}
ll get (ll p)
{
p1 = far(p);
p2 = far(p1);
len = mx ;
best = oo ;
dfs2(p1 , p1 , 0 , p2) ;
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 far(ll)':
dreaming.cpp:75:12: warning: 'ret' may be used uninitialized in this function [-Wmaybe-uninitialized]
75 | return ret ;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
37060 KB |
Output is correct |
2 |
Correct |
55 ms |
37072 KB |
Output is correct |
3 |
Correct |
40 ms |
32404 KB |
Output is correct |
4 |
Correct |
18 ms |
25684 KB |
Output is correct |
5 |
Correct |
18 ms |
24972 KB |
Output is correct |
6 |
Correct |
23 ms |
26884 KB |
Output is correct |
7 |
Correct |
12 ms |
23764 KB |
Output is correct |
8 |
Correct |
38 ms |
28616 KB |
Output is correct |
9 |
Correct |
51 ms |
30520 KB |
Output is correct |
10 |
Correct |
13 ms |
23796 KB |
Output is correct |
11 |
Correct |
57 ms |
32604 KB |
Output is correct |
12 |
Correct |
71 ms |
34872 KB |
Output is correct |
13 |
Correct |
13 ms |
23892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
23768 KB |
Output is correct |
3 |
Correct |
13 ms |
23764 KB |
Output is correct |
4 |
Correct |
12 ms |
23764 KB |
Output is correct |
5 |
Correct |
13 ms |
23688 KB |
Output is correct |
6 |
Correct |
13 ms |
23764 KB |
Output is correct |
7 |
Correct |
13 ms |
23764 KB |
Output is correct |
8 |
Correct |
13 ms |
23820 KB |
Output is correct |
9 |
Correct |
13 ms |
23764 KB |
Output is correct |
10 |
Correct |
13 ms |
23764 KB |
Output is correct |
11 |
Correct |
13 ms |
23764 KB |
Output is correct |
12 |
Correct |
12 ms |
23764 KB |
Output is correct |
13 |
Correct |
12 ms |
23764 KB |
Output is correct |
14 |
Correct |
12 ms |
23764 KB |
Output is correct |
15 |
Correct |
12 ms |
23764 KB |
Output is correct |
16 |
Correct |
13 ms |
23724 KB |
Output is correct |
17 |
Correct |
12 ms |
23824 KB |
Output is correct |
18 |
Correct |
12 ms |
23756 KB |
Output is correct |
19 |
Correct |
13 ms |
23764 KB |
Output is correct |
20 |
Correct |
12 ms |
23764 KB |
Output is correct |
21 |
Correct |
13 ms |
23828 KB |
Output is correct |
22 |
Correct |
12 ms |
23764 KB |
Output is correct |
23 |
Correct |
12 ms |
23720 KB |
Output is correct |
24 |
Correct |
15 ms |
23804 KB |
Output is correct |
25 |
Correct |
13 ms |
23812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
37060 KB |
Output is correct |
2 |
Correct |
55 ms |
37072 KB |
Output is correct |
3 |
Correct |
40 ms |
32404 KB |
Output is correct |
4 |
Correct |
18 ms |
25684 KB |
Output is correct |
5 |
Correct |
18 ms |
24972 KB |
Output is correct |
6 |
Correct |
23 ms |
26884 KB |
Output is correct |
7 |
Correct |
12 ms |
23764 KB |
Output is correct |
8 |
Correct |
38 ms |
28616 KB |
Output is correct |
9 |
Correct |
51 ms |
30520 KB |
Output is correct |
10 |
Correct |
13 ms |
23796 KB |
Output is correct |
11 |
Correct |
57 ms |
32604 KB |
Output is correct |
12 |
Correct |
71 ms |
34872 KB |
Output is correct |
13 |
Correct |
13 ms |
23892 KB |
Output is correct |
14 |
Correct |
12 ms |
23764 KB |
Output is correct |
15 |
Correct |
13 ms |
23768 KB |
Output is correct |
16 |
Correct |
13 ms |
23764 KB |
Output is correct |
17 |
Correct |
12 ms |
23764 KB |
Output is correct |
18 |
Correct |
13 ms |
23688 KB |
Output is correct |
19 |
Correct |
13 ms |
23764 KB |
Output is correct |
20 |
Correct |
13 ms |
23764 KB |
Output is correct |
21 |
Correct |
13 ms |
23820 KB |
Output is correct |
22 |
Correct |
13 ms |
23764 KB |
Output is correct |
23 |
Correct |
13 ms |
23764 KB |
Output is correct |
24 |
Correct |
13 ms |
23764 KB |
Output is correct |
25 |
Correct |
12 ms |
23764 KB |
Output is correct |
26 |
Correct |
12 ms |
23764 KB |
Output is correct |
27 |
Correct |
12 ms |
23764 KB |
Output is correct |
28 |
Correct |
12 ms |
23764 KB |
Output is correct |
29 |
Correct |
13 ms |
23724 KB |
Output is correct |
30 |
Correct |
12 ms |
23824 KB |
Output is correct |
31 |
Correct |
12 ms |
23756 KB |
Output is correct |
32 |
Correct |
13 ms |
23764 KB |
Output is correct |
33 |
Correct |
12 ms |
23764 KB |
Output is correct |
34 |
Correct |
13 ms |
23828 KB |
Output is correct |
35 |
Correct |
12 ms |
23764 KB |
Output is correct |
36 |
Correct |
12 ms |
23720 KB |
Output is correct |
37 |
Correct |
15 ms |
23804 KB |
Output is correct |
38 |
Correct |
13 ms |
23812 KB |
Output is correct |
39 |
Correct |
57 ms |
37084 KB |
Output is correct |
40 |
Correct |
56 ms |
37052 KB |
Output is correct |
41 |
Correct |
42 ms |
32496 KB |
Output is correct |
42 |
Correct |
18 ms |
25660 KB |
Output is correct |
43 |
Correct |
13 ms |
23764 KB |
Output is correct |
44 |
Correct |
13 ms |
23764 KB |
Output is correct |
45 |
Correct |
13 ms |
23764 KB |
Output is correct |
46 |
Correct |
12 ms |
23764 KB |
Output is correct |
47 |
Correct |
13 ms |
23816 KB |
Output is correct |
48 |
Correct |
12 ms |
23748 KB |
Output is correct |
49 |
Correct |
14 ms |
23792 KB |
Output is correct |
50 |
Correct |
12 ms |
23816 KB |
Output is correct |
51 |
Correct |
14 ms |
23772 KB |
Output is correct |
52 |
Correct |
14 ms |
23764 KB |
Output is correct |
53 |
Correct |
15 ms |
23740 KB |
Output is correct |
54 |
Correct |
12 ms |
23764 KB |
Output is correct |
55 |
Correct |
14 ms |
23764 KB |
Output is correct |
56 |
Correct |
12 ms |
23752 KB |
Output is correct |
57 |
Correct |
81 ms |
31692 KB |
Output is correct |
58 |
Correct |
104 ms |
31720 KB |
Output is correct |
59 |
Correct |
81 ms |
31404 KB |
Output is correct |
60 |
Correct |
81 ms |
31452 KB |
Output is correct |
61 |
Correct |
84 ms |
31244 KB |
Output is correct |
62 |
Correct |
81 ms |
31264 KB |
Output is correct |
63 |
Incorrect |
78 ms |
30992 KB |
Output isn't correct |
64 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
26 ms |
26832 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
23768 KB |
Output is correct |
3 |
Correct |
13 ms |
23764 KB |
Output is correct |
4 |
Correct |
12 ms |
23764 KB |
Output is correct |
5 |
Correct |
13 ms |
23688 KB |
Output is correct |
6 |
Correct |
13 ms |
23764 KB |
Output is correct |
7 |
Correct |
13 ms |
23764 KB |
Output is correct |
8 |
Correct |
13 ms |
23820 KB |
Output is correct |
9 |
Correct |
13 ms |
23764 KB |
Output is correct |
10 |
Correct |
13 ms |
23764 KB |
Output is correct |
11 |
Correct |
13 ms |
23764 KB |
Output is correct |
12 |
Correct |
12 ms |
23764 KB |
Output is correct |
13 |
Correct |
12 ms |
23764 KB |
Output is correct |
14 |
Correct |
12 ms |
23764 KB |
Output is correct |
15 |
Correct |
12 ms |
23764 KB |
Output is correct |
16 |
Correct |
13 ms |
23724 KB |
Output is correct |
17 |
Correct |
12 ms |
23824 KB |
Output is correct |
18 |
Correct |
12 ms |
23756 KB |
Output is correct |
19 |
Correct |
13 ms |
23764 KB |
Output is correct |
20 |
Correct |
12 ms |
23764 KB |
Output is correct |
21 |
Correct |
13 ms |
23828 KB |
Output is correct |
22 |
Correct |
12 ms |
23764 KB |
Output is correct |
23 |
Correct |
12 ms |
23720 KB |
Output is correct |
24 |
Correct |
15 ms |
23804 KB |
Output is correct |
25 |
Correct |
13 ms |
23812 KB |
Output is correct |
26 |
Correct |
13 ms |
23764 KB |
Output is correct |
27 |
Incorrect |
14 ms |
23936 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
37060 KB |
Output is correct |
2 |
Correct |
55 ms |
37072 KB |
Output is correct |
3 |
Correct |
40 ms |
32404 KB |
Output is correct |
4 |
Correct |
18 ms |
25684 KB |
Output is correct |
5 |
Correct |
18 ms |
24972 KB |
Output is correct |
6 |
Correct |
23 ms |
26884 KB |
Output is correct |
7 |
Correct |
12 ms |
23764 KB |
Output is correct |
8 |
Correct |
38 ms |
28616 KB |
Output is correct |
9 |
Correct |
51 ms |
30520 KB |
Output is correct |
10 |
Correct |
13 ms |
23796 KB |
Output is correct |
11 |
Correct |
57 ms |
32604 KB |
Output is correct |
12 |
Correct |
71 ms |
34872 KB |
Output is correct |
13 |
Correct |
13 ms |
23892 KB |
Output is correct |
14 |
Correct |
12 ms |
23764 KB |
Output is correct |
15 |
Correct |
13 ms |
23768 KB |
Output is correct |
16 |
Correct |
13 ms |
23764 KB |
Output is correct |
17 |
Correct |
12 ms |
23764 KB |
Output is correct |
18 |
Correct |
13 ms |
23688 KB |
Output is correct |
19 |
Correct |
13 ms |
23764 KB |
Output is correct |
20 |
Correct |
13 ms |
23764 KB |
Output is correct |
21 |
Correct |
13 ms |
23820 KB |
Output is correct |
22 |
Correct |
13 ms |
23764 KB |
Output is correct |
23 |
Correct |
13 ms |
23764 KB |
Output is correct |
24 |
Correct |
13 ms |
23764 KB |
Output is correct |
25 |
Correct |
12 ms |
23764 KB |
Output is correct |
26 |
Correct |
12 ms |
23764 KB |
Output is correct |
27 |
Correct |
12 ms |
23764 KB |
Output is correct |
28 |
Correct |
12 ms |
23764 KB |
Output is correct |
29 |
Correct |
13 ms |
23724 KB |
Output is correct |
30 |
Correct |
12 ms |
23824 KB |
Output is correct |
31 |
Correct |
12 ms |
23756 KB |
Output is correct |
32 |
Correct |
13 ms |
23764 KB |
Output is correct |
33 |
Correct |
12 ms |
23764 KB |
Output is correct |
34 |
Correct |
13 ms |
23828 KB |
Output is correct |
35 |
Correct |
12 ms |
23764 KB |
Output is correct |
36 |
Correct |
12 ms |
23720 KB |
Output is correct |
37 |
Correct |
15 ms |
23804 KB |
Output is correct |
38 |
Correct |
13 ms |
23812 KB |
Output is correct |
39 |
Correct |
57 ms |
37084 KB |
Output is correct |
40 |
Correct |
56 ms |
37052 KB |
Output is correct |
41 |
Correct |
42 ms |
32496 KB |
Output is correct |
42 |
Correct |
18 ms |
25660 KB |
Output is correct |
43 |
Correct |
13 ms |
23764 KB |
Output is correct |
44 |
Correct |
13 ms |
23764 KB |
Output is correct |
45 |
Correct |
13 ms |
23764 KB |
Output is correct |
46 |
Correct |
12 ms |
23764 KB |
Output is correct |
47 |
Correct |
13 ms |
23816 KB |
Output is correct |
48 |
Correct |
12 ms |
23748 KB |
Output is correct |
49 |
Correct |
14 ms |
23792 KB |
Output is correct |
50 |
Correct |
12 ms |
23816 KB |
Output is correct |
51 |
Correct |
14 ms |
23772 KB |
Output is correct |
52 |
Correct |
14 ms |
23764 KB |
Output is correct |
53 |
Correct |
15 ms |
23740 KB |
Output is correct |
54 |
Correct |
12 ms |
23764 KB |
Output is correct |
55 |
Correct |
14 ms |
23764 KB |
Output is correct |
56 |
Correct |
12 ms |
23752 KB |
Output is correct |
57 |
Correct |
81 ms |
31692 KB |
Output is correct |
58 |
Correct |
104 ms |
31720 KB |
Output is correct |
59 |
Correct |
81 ms |
31404 KB |
Output is correct |
60 |
Correct |
81 ms |
31452 KB |
Output is correct |
61 |
Correct |
84 ms |
31244 KB |
Output is correct |
62 |
Correct |
81 ms |
31264 KB |
Output is correct |
63 |
Incorrect |
78 ms |
30992 KB |
Output isn't correct |
64 |
Halted |
0 ms |
0 KB |
- |