#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std ;
#define pii pair <int , int>
#define ff first
#define ss second
const int inf = 1e9 ;
const int N = 1e5 + 5 ;
template <class T>
bool chmax( T& x , const T& y ){
bool f = 0 ;
if ( x < y ) x = y , f = 1 ;
return f ;
}
template <class T>
bool chmin( T &x , const T &y ){
bool f = 0 ;
if ( x > y ) x = y , f = 1 ;
return f ;
}
bool vis[N] ;
int d[N] , f[N] , sc[N] ;
int mx , m , ind , r ;
pii ans[N] ;
vector <pii> g[N] ;
void dfs ( int v , int s , int& m ){
vis[v] = 1 ; d[v] = s ;
if ( mx <= d[v] ){
m = v ; mx = d[v] ;
}
for ( auto to : g[v] ) if ( !vis[to.ff] ) dfs(to.ff,s+to.ss,m) ;
}
void fir ( int v , int d , int& m ){
vis[v] = 0 ; f[v] = d ;
if ( chmax ( mx , f[v] ) ) m = v ;
for ( auto to : g[v] ) if ( vis[to.ff] ) fir(to.ff,d+to.ss,m) ;
}
void sec ( int v , int d , int& m ){
vis[v] = 1 ; sc[v] = d ;
if ( max( f[v] , sc[v] ) < mx ){
mx = max ( f[v] , sc[v] ) ; m = v ;
}
for ( auto to : g[v] ) if ( !vis[to.ff] ) sec(to.ff,d+to.ss,m) ;
}
int travelTime(int n, int m, int l, int a[], int b[], int c[]) {
for ( int i = 0 ; i < m ; i ++ ){
g[a[i]].push_back({b[i],c[i]}) ;
g[b[i]].push_back({a[i],c[i]}) ;
}
for ( int i = 1 ; i <= n ; i ++ ){
if ( !vis[i] ){
mx = 0 ;
dfs(i,0,m) ;
mx = 0 ;
fir(m,0,m) ;
chmax ( r , f[m] ) ;
mx = inf ;
sec(m,0,m) ;
ans[ind].ff = f[m] ;
ans[ind].ss = sc[m] ;
ind ++ ;
}
}
return max (r,l + max(ans[0].ff,ans[0].ss) + max( ans[1].ff , ans[1].ss )) ;
}
/*
signed main(){
int n , m , l , a[N] , b[N] , t[N] ;
cin >> n >> m >> l ;
for ( int i = 0 ; i < m ; i ++ ) cin >> a[i] >> b[i] >> t[i] ;
cout << travelTime( n , m , l , a , b , t ) ;
}
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
12900 KB |
Output is correct |
2 |
Correct |
30 ms |
13312 KB |
Output is correct |
3 |
Correct |
24 ms |
10240 KB |
Output is correct |
4 |
Correct |
5 ms |
5976 KB |
Output is correct |
5 |
Correct |
4 ms |
5208 KB |
Output is correct |
6 |
Correct |
9 ms |
6492 KB |
Output is correct |
7 |
Correct |
2 ms |
4444 KB |
Output is correct |
8 |
Correct |
18 ms |
7444 KB |
Output is correct |
9 |
Correct |
21 ms |
8584 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
28 ms |
10004 KB |
Output is correct |
12 |
Correct |
31 ms |
11356 KB |
Output is correct |
13 |
Correct |
1 ms |
4696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4524 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4536 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
12900 KB |
Output is correct |
2 |
Correct |
30 ms |
13312 KB |
Output is correct |
3 |
Correct |
24 ms |
10240 KB |
Output is correct |
4 |
Correct |
5 ms |
5976 KB |
Output is correct |
5 |
Correct |
4 ms |
5208 KB |
Output is correct |
6 |
Correct |
9 ms |
6492 KB |
Output is correct |
7 |
Correct |
2 ms |
4444 KB |
Output is correct |
8 |
Correct |
18 ms |
7444 KB |
Output is correct |
9 |
Correct |
21 ms |
8584 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
28 ms |
10004 KB |
Output is correct |
12 |
Correct |
31 ms |
11356 KB |
Output is correct |
13 |
Correct |
1 ms |
4696 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4524 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
33 |
Correct |
1 ms |
4536 KB |
Output is correct |
34 |
Correct |
1 ms |
4444 KB |
Output is correct |
35 |
Correct |
1 ms |
4444 KB |
Output is correct |
36 |
Correct |
1 ms |
4444 KB |
Output is correct |
37 |
Correct |
1 ms |
4444 KB |
Output is correct |
38 |
Correct |
1 ms |
4444 KB |
Output is correct |
39 |
Correct |
29 ms |
12892 KB |
Output is correct |
40 |
Correct |
31 ms |
13176 KB |
Output is correct |
41 |
Correct |
21 ms |
10292 KB |
Output is correct |
42 |
Correct |
5 ms |
5724 KB |
Output is correct |
43 |
Correct |
1 ms |
4444 KB |
Output is correct |
44 |
Correct |
1 ms |
4440 KB |
Output is correct |
45 |
Correct |
1 ms |
4456 KB |
Output is correct |
46 |
Correct |
1 ms |
4444 KB |
Output is correct |
47 |
Correct |
1 ms |
4548 KB |
Output is correct |
48 |
Correct |
1 ms |
4444 KB |
Output is correct |
49 |
Correct |
1 ms |
4444 KB |
Output is correct |
50 |
Correct |
1 ms |
4444 KB |
Output is correct |
51 |
Correct |
1 ms |
4444 KB |
Output is correct |
52 |
Correct |
2 ms |
4444 KB |
Output is correct |
53 |
Correct |
1 ms |
4444 KB |
Output is correct |
54 |
Correct |
1 ms |
4444 KB |
Output is correct |
55 |
Correct |
1 ms |
4444 KB |
Output is correct |
56 |
Correct |
1 ms |
4440 KB |
Output is correct |
57 |
Correct |
39 ms |
10360 KB |
Output is correct |
58 |
Correct |
37 ms |
10072 KB |
Output is correct |
59 |
Correct |
48 ms |
10132 KB |
Output is correct |
60 |
Correct |
40 ms |
10224 KB |
Output is correct |
61 |
Correct |
40 ms |
10084 KB |
Output is correct |
62 |
Correct |
37 ms |
10068 KB |
Output is correct |
63 |
Correct |
34 ms |
9812 KB |
Output is correct |
64 |
Correct |
39 ms |
9916 KB |
Output is correct |
65 |
Correct |
38 ms |
10076 KB |
Output is correct |
66 |
Correct |
36 ms |
10136 KB |
Output is correct |
67 |
Correct |
46 ms |
10524 KB |
Output is correct |
68 |
Correct |
38 ms |
10004 KB |
Output is correct |
69 |
Correct |
40 ms |
10320 KB |
Output is correct |
70 |
Correct |
38 ms |
9992 KB |
Output is correct |
71 |
Correct |
1 ms |
4440 KB |
Output is correct |
72 |
Correct |
2 ms |
4696 KB |
Output is correct |
73 |
Correct |
2 ms |
4696 KB |
Output is correct |
74 |
Correct |
3 ms |
4696 KB |
Output is correct |
75 |
Correct |
2 ms |
4700 KB |
Output is correct |
76 |
Correct |
2 ms |
4700 KB |
Output is correct |
77 |
Correct |
2 ms |
4700 KB |
Output is correct |
78 |
Correct |
2 ms |
4700 KB |
Output is correct |
79 |
Correct |
2 ms |
4700 KB |
Output is correct |
80 |
Correct |
37 ms |
10228 KB |
Output is correct |
81 |
Correct |
38 ms |
10068 KB |
Output is correct |
82 |
Correct |
37 ms |
10072 KB |
Output is correct |
83 |
Correct |
37 ms |
9812 KB |
Output is correct |
84 |
Correct |
1 ms |
4700 KB |
Output is correct |
85 |
Correct |
1 ms |
4444 KB |
Output is correct |
86 |
Correct |
2 ms |
4696 KB |
Output is correct |
87 |
Correct |
2 ms |
4700 KB |
Output is correct |
88 |
Correct |
2 ms |
4700 KB |
Output is correct |
89 |
Correct |
2 ms |
4700 KB |
Output is correct |
90 |
Correct |
2 ms |
4700 KB |
Output is correct |
91 |
Correct |
2 ms |
4700 KB |
Output is correct |
92 |
Correct |
2 ms |
4700 KB |
Output is correct |
93 |
Correct |
2 ms |
4700 KB |
Output is correct |
94 |
Correct |
1 ms |
4444 KB |
Output is correct |
95 |
Correct |
1 ms |
4444 KB |
Output is correct |
96 |
Correct |
1 ms |
4444 KB |
Output is correct |
97 |
Correct |
1 ms |
4444 KB |
Output is correct |
98 |
Correct |
1 ms |
4444 KB |
Output is correct |
99 |
Correct |
1 ms |
4444 KB |
Output is correct |
100 |
Correct |
1 ms |
4444 KB |
Output is correct |
101 |
Correct |
1 ms |
4440 KB |
Output is correct |
102 |
Correct |
1 ms |
4440 KB |
Output is correct |
103 |
Correct |
1 ms |
4440 KB |
Output is correct |
104 |
Correct |
4 ms |
5088 KB |
Output is correct |
105 |
Correct |
9 ms |
6488 KB |
Output is correct |
106 |
Correct |
1 ms |
4444 KB |
Output is correct |
107 |
Correct |
16 ms |
7516 KB |
Output is correct |
108 |
Correct |
25 ms |
8848 KB |
Output is correct |
109 |
Correct |
1 ms |
4444 KB |
Output is correct |
110 |
Correct |
31 ms |
10092 KB |
Output is correct |
111 |
Correct |
36 ms |
11400 KB |
Output is correct |
112 |
Correct |
1 ms |
4440 KB |
Output is correct |
113 |
Correct |
46 ms |
13640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
7772 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4524 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4536 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
2 ms |
4696 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
31 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
12900 KB |
Output is correct |
2 |
Correct |
30 ms |
13312 KB |
Output is correct |
3 |
Correct |
24 ms |
10240 KB |
Output is correct |
4 |
Correct |
5 ms |
5976 KB |
Output is correct |
5 |
Correct |
4 ms |
5208 KB |
Output is correct |
6 |
Correct |
9 ms |
6492 KB |
Output is correct |
7 |
Correct |
2 ms |
4444 KB |
Output is correct |
8 |
Correct |
18 ms |
7444 KB |
Output is correct |
9 |
Correct |
21 ms |
8584 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
28 ms |
10004 KB |
Output is correct |
12 |
Correct |
31 ms |
11356 KB |
Output is correct |
13 |
Correct |
1 ms |
4696 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4524 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
33 |
Correct |
1 ms |
4536 KB |
Output is correct |
34 |
Correct |
1 ms |
4444 KB |
Output is correct |
35 |
Correct |
1 ms |
4444 KB |
Output is correct |
36 |
Correct |
1 ms |
4444 KB |
Output is correct |
37 |
Correct |
1 ms |
4444 KB |
Output is correct |
38 |
Correct |
1 ms |
4444 KB |
Output is correct |
39 |
Correct |
29 ms |
12892 KB |
Output is correct |
40 |
Correct |
31 ms |
13176 KB |
Output is correct |
41 |
Correct |
21 ms |
10292 KB |
Output is correct |
42 |
Correct |
5 ms |
5724 KB |
Output is correct |
43 |
Correct |
1 ms |
4444 KB |
Output is correct |
44 |
Correct |
1 ms |
4440 KB |
Output is correct |
45 |
Correct |
1 ms |
4456 KB |
Output is correct |
46 |
Correct |
1 ms |
4444 KB |
Output is correct |
47 |
Correct |
1 ms |
4548 KB |
Output is correct |
48 |
Correct |
1 ms |
4444 KB |
Output is correct |
49 |
Correct |
1 ms |
4444 KB |
Output is correct |
50 |
Correct |
1 ms |
4444 KB |
Output is correct |
51 |
Correct |
1 ms |
4444 KB |
Output is correct |
52 |
Correct |
2 ms |
4444 KB |
Output is correct |
53 |
Correct |
1 ms |
4444 KB |
Output is correct |
54 |
Correct |
1 ms |
4444 KB |
Output is correct |
55 |
Correct |
1 ms |
4444 KB |
Output is correct |
56 |
Correct |
1 ms |
4440 KB |
Output is correct |
57 |
Correct |
39 ms |
10360 KB |
Output is correct |
58 |
Correct |
37 ms |
10072 KB |
Output is correct |
59 |
Correct |
48 ms |
10132 KB |
Output is correct |
60 |
Correct |
40 ms |
10224 KB |
Output is correct |
61 |
Correct |
40 ms |
10084 KB |
Output is correct |
62 |
Correct |
37 ms |
10068 KB |
Output is correct |
63 |
Correct |
34 ms |
9812 KB |
Output is correct |
64 |
Correct |
39 ms |
9916 KB |
Output is correct |
65 |
Correct |
38 ms |
10076 KB |
Output is correct |
66 |
Correct |
36 ms |
10136 KB |
Output is correct |
67 |
Correct |
46 ms |
10524 KB |
Output is correct |
68 |
Correct |
38 ms |
10004 KB |
Output is correct |
69 |
Correct |
40 ms |
10320 KB |
Output is correct |
70 |
Correct |
38 ms |
9992 KB |
Output is correct |
71 |
Correct |
1 ms |
4440 KB |
Output is correct |
72 |
Correct |
2 ms |
4696 KB |
Output is correct |
73 |
Correct |
2 ms |
4696 KB |
Output is correct |
74 |
Correct |
3 ms |
4696 KB |
Output is correct |
75 |
Correct |
2 ms |
4700 KB |
Output is correct |
76 |
Correct |
2 ms |
4700 KB |
Output is correct |
77 |
Correct |
2 ms |
4700 KB |
Output is correct |
78 |
Correct |
2 ms |
4700 KB |
Output is correct |
79 |
Correct |
2 ms |
4700 KB |
Output is correct |
80 |
Correct |
37 ms |
10228 KB |
Output is correct |
81 |
Correct |
38 ms |
10068 KB |
Output is correct |
82 |
Correct |
37 ms |
10072 KB |
Output is correct |
83 |
Correct |
37 ms |
9812 KB |
Output is correct |
84 |
Correct |
1 ms |
4700 KB |
Output is correct |
85 |
Correct |
1 ms |
4444 KB |
Output is correct |
86 |
Correct |
2 ms |
4696 KB |
Output is correct |
87 |
Correct |
2 ms |
4700 KB |
Output is correct |
88 |
Correct |
2 ms |
4700 KB |
Output is correct |
89 |
Correct |
2 ms |
4700 KB |
Output is correct |
90 |
Correct |
2 ms |
4700 KB |
Output is correct |
91 |
Correct |
2 ms |
4700 KB |
Output is correct |
92 |
Correct |
2 ms |
4700 KB |
Output is correct |
93 |
Correct |
2 ms |
4700 KB |
Output is correct |
94 |
Correct |
1 ms |
4444 KB |
Output is correct |
95 |
Correct |
1 ms |
4444 KB |
Output is correct |
96 |
Correct |
1 ms |
4444 KB |
Output is correct |
97 |
Correct |
1 ms |
4444 KB |
Output is correct |
98 |
Correct |
1 ms |
4444 KB |
Output is correct |
99 |
Correct |
1 ms |
4444 KB |
Output is correct |
100 |
Correct |
1 ms |
4444 KB |
Output is correct |
101 |
Correct |
1 ms |
4440 KB |
Output is correct |
102 |
Correct |
1 ms |
4440 KB |
Output is correct |
103 |
Correct |
1 ms |
4440 KB |
Output is correct |
104 |
Correct |
4 ms |
5088 KB |
Output is correct |
105 |
Correct |
9 ms |
6488 KB |
Output is correct |
106 |
Correct |
1 ms |
4444 KB |
Output is correct |
107 |
Correct |
16 ms |
7516 KB |
Output is correct |
108 |
Correct |
25 ms |
8848 KB |
Output is correct |
109 |
Correct |
1 ms |
4444 KB |
Output is correct |
110 |
Correct |
31 ms |
10092 KB |
Output is correct |
111 |
Correct |
36 ms |
11400 KB |
Output is correct |
112 |
Correct |
1 ms |
4440 KB |
Output is correct |
113 |
Correct |
46 ms |
13640 KB |
Output is correct |
114 |
Incorrect |
12 ms |
7772 KB |
Output isn't correct |
115 |
Halted |
0 ms |
0 KB |
- |