#include "dreaming.h"
#include <vector>
#define N 100001
#define INF 2000000000
using namespace std;
int n, L, out, max_len, MAX1, MAX2;
int gd[N];
bool check[N], gd_check[N];
vector<pair<int,int> > r[N];
int max_f(int x, int y) { return x>y?x:y; }
int min_f(int x, int y) { return x<y?x:y; }
int g(int lev, int up_node){
if(!gd_check[lev]){
gd_check[lev]=true;
for(vector<pair<int,int> >::iterator it=r[lev].begin(); it!=r[lev].end(); it++)
if(it->first!=up_node) gd[lev]=max_f(gd[lev],it->second+g(it->first,lev));
}
return gd[lev];
}
void f(int lev, int up_len){
int max1=0, max2=0, path, temp;
check[lev]=true;
for(vector<pair<int,int> >::iterator it=r[lev].begin(); it!=r[lev].end(); it++) {
if(!check[it->first]) temp=g(it->first,lev)+it->second;
else temp=up_len;
if(max1<temp){
max2=max1, max1=temp;
path=it->first;
}
else if(max2<temp) max2=temp;
}
out=max_f(out,max1+max2);
max_len=min_f(max_len,max1);
for(vector<pair<int,int> >::iterator it=r[lev].begin(); it!=r[lev].end(); it++)
if(!check[it->first]) f(it->first,(path==it->first?max2:max1)+it->second);
}
int travelTime(int _n, int m, int _L, int _a[], int _b[], int _t[]) {
int x, y;
n=_n, L=_L;
for(int i=0; i<m; i++){
x=_a[i]+1, y=_b[i]+1;
r[x].push_back({y,_t[i]}), r[y].push_back({x,_t[i]});
}
for(int i=1; i<=n; i++)
if(!check[i]){
max_len=INF, f(i,0);
if(MAX1<max_len) MAX2=MAX1, MAX1=max_len;
else if(MAX2<max_len) MAX2=max_len;
}
return max_f(out,MAX1+MAX2+L);
}
Compilation message
dreaming.cpp: In function 'void f(int, int)':
dreaming.cpp:41:59: warning: 'path' may be used uninitialized in this function [-Wmaybe-uninitialized]
if(!check[it->first]) f(it->first,(path==it->first?max2:max1)+it->second);
~~~~~~~~~~~~~~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
10232 KB |
Output is correct |
2 |
Correct |
59 ms |
9968 KB |
Output is correct |
3 |
Correct |
40 ms |
8824 KB |
Output is correct |
4 |
Correct |
13 ms |
3712 KB |
Output is correct |
5 |
Correct |
10 ms |
3328 KB |
Output is correct |
6 |
Correct |
17 ms |
4352 KB |
Output is correct |
7 |
Correct |
4 ms |
2688 KB |
Output is correct |
8 |
Correct |
29 ms |
5996 KB |
Output is correct |
9 |
Correct |
42 ms |
7672 KB |
Output is correct |
10 |
Correct |
4 ms |
2816 KB |
Output is correct |
11 |
Correct |
48 ms |
8184 KB |
Output is correct |
12 |
Correct |
55 ms |
9212 KB |
Output is correct |
13 |
Correct |
5 ms |
2816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
10232 KB |
Output is correct |
2 |
Correct |
59 ms |
9968 KB |
Output is correct |
3 |
Correct |
40 ms |
8824 KB |
Output is correct |
4 |
Correct |
13 ms |
3712 KB |
Output is correct |
5 |
Correct |
10 ms |
3328 KB |
Output is correct |
6 |
Correct |
17 ms |
4352 KB |
Output is correct |
7 |
Correct |
4 ms |
2688 KB |
Output is correct |
8 |
Correct |
29 ms |
5996 KB |
Output is correct |
9 |
Correct |
42 ms |
7672 KB |
Output is correct |
10 |
Correct |
4 ms |
2816 KB |
Output is correct |
11 |
Correct |
48 ms |
8184 KB |
Output is correct |
12 |
Correct |
55 ms |
9212 KB |
Output is correct |
13 |
Correct |
5 ms |
2816 KB |
Output is correct |
14 |
Correct |
3 ms |
2688 KB |
Output is correct |
15 |
Correct |
3 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 |
4 ms |
2688 KB |
Output is correct |
20 |
Correct |
3 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 |
4 ms |
2688 KB |
Output is correct |
25 |
Correct |
4 ms |
2688 KB |
Output is correct |
26 |
Correct |
3 ms |
2688 KB |
Output is correct |
27 |
Correct |
3 ms |
2688 KB |
Output is correct |
28 |
Correct |
3 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 |
2688 KB |
Output is correct |
34 |
Correct |
4 ms |
2688 KB |
Output is correct |
35 |
Correct |
3 ms |
2688 KB |
Output is correct |
36 |
Correct |
4 ms |
2688 KB |
Output is correct |
37 |
Correct |
5 ms |
2688 KB |
Output is correct |
38 |
Correct |
4 ms |
2688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
10232 KB |
Output is correct |
2 |
Correct |
59 ms |
9968 KB |
Output is correct |
3 |
Correct |
40 ms |
8824 KB |
Output is correct |
4 |
Correct |
13 ms |
3712 KB |
Output is correct |
5 |
Correct |
10 ms |
3328 KB |
Output is correct |
6 |
Correct |
17 ms |
4352 KB |
Output is correct |
7 |
Correct |
4 ms |
2688 KB |
Output is correct |
8 |
Correct |
29 ms |
5996 KB |
Output is correct |
9 |
Correct |
42 ms |
7672 KB |
Output is correct |
10 |
Correct |
4 ms |
2816 KB |
Output is correct |
11 |
Correct |
48 ms |
8184 KB |
Output is correct |
12 |
Correct |
55 ms |
9212 KB |
Output is correct |
13 |
Correct |
5 ms |
2816 KB |
Output is correct |
14 |
Correct |
3 ms |
2688 KB |
Output is correct |
15 |
Correct |
3 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 |
4 ms |
2688 KB |
Output is correct |
20 |
Correct |
3 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 |
4 ms |
2688 KB |
Output is correct |
25 |
Correct |
4 ms |
2688 KB |
Output is correct |
26 |
Correct |
3 ms |
2688 KB |
Output is correct |
27 |
Correct |
3 ms |
2688 KB |
Output is correct |
28 |
Correct |
3 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 |
2688 KB |
Output is correct |
34 |
Correct |
4 ms |
2688 KB |
Output is correct |
35 |
Correct |
3 ms |
2688 KB |
Output is correct |
36 |
Correct |
4 ms |
2688 KB |
Output is correct |
37 |
Correct |
5 ms |
2688 KB |
Output is correct |
38 |
Correct |
4 ms |
2688 KB |
Output is correct |
39 |
Correct |
58 ms |
10420 KB |
Output is correct |
40 |
Correct |
55 ms |
9976 KB |
Output is correct |
41 |
Correct |
38 ms |
8824 KB |
Output is correct |
42 |
Correct |
10 ms |
3840 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 |
2816 KB |
Output is correct |
51 |
Correct |
3 ms |
2688 KB |
Output is correct |
52 |
Correct |
4 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 |
72 ms |
8440 KB |
Output is correct |
58 |
Correct |
87 ms |
8444 KB |
Output is correct |
59 |
Correct |
73 ms |
8264 KB |
Output is correct |
60 |
Correct |
83 ms |
8312 KB |
Output is correct |
61 |
Correct |
68 ms |
8312 KB |
Output is correct |
62 |
Correct |
82 ms |
8312 KB |
Output is correct |
63 |
Correct |
64 ms |
8184 KB |
Output is correct |
64 |
Correct |
92 ms |
8056 KB |
Output is correct |
65 |
Correct |
67 ms |
8056 KB |
Output is correct |
66 |
Correct |
90 ms |
8056 KB |
Output is correct |
67 |
Correct |
76 ms |
8312 KB |
Output is correct |
68 |
Correct |
77 ms |
8312 KB |
Output is correct |
69 |
Correct |
76 ms |
8312 KB |
Output is correct |
70 |
Correct |
95 ms |
8316 KB |
Output is correct |
71 |
Correct |
3 ms |
2688 KB |
Output is correct |
72 |
Correct |
4 ms |
2816 KB |
Output is correct |
73 |
Correct |
5 ms |
2816 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 |
2816 KB |
Output is correct |
77 |
Correct |
5 ms |
2816 KB |
Output is correct |
78 |
Correct |
7 ms |
2816 KB |
Output is correct |
79 |
Correct |
5 ms |
2816 KB |
Output is correct |
80 |
Correct |
142 ms |
8312 KB |
Output is correct |
81 |
Correct |
78 ms |
8312 KB |
Output is correct |
82 |
Correct |
87 ms |
8184 KB |
Output is correct |
83 |
Correct |
64 ms |
8312 KB |
Output is correct |
84 |
Correct |
6 ms |
2816 KB |
Output is correct |
85 |
Correct |
4 ms |
2788 KB |
Output is correct |
86 |
Correct |
5 ms |
2816 KB |
Output is correct |
87 |
Correct |
5 ms |
2816 KB |
Output is correct |
88 |
Correct |
5 ms |
2816 KB |
Output is correct |
89 |
Correct |
5 ms |
2788 KB |
Output is correct |
90 |
Correct |
6 ms |
2816 KB |
Output is correct |
91 |
Correct |
5 ms |
2816 KB |
Output is correct |
92 |
Correct |
5 ms |
2816 KB |
Output is correct |
93 |
Correct |
5 ms |
2816 KB |
Output is correct |
94 |
Correct |
4 ms |
2688 KB |
Output is correct |
95 |
Correct |
3 ms |
2688 KB |
Output is correct |
96 |
Correct |
4 ms |
2688 KB |
Output is correct |
97 |
Correct |
3 ms |
2688 KB |
Output is correct |
98 |
Correct |
5 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 |
2660 KB |
Output is correct |
104 |
Correct |
9 ms |
3328 KB |
Output is correct |
105 |
Correct |
15 ms |
4352 KB |
Output is correct |
106 |
Correct |
3 ms |
2688 KB |
Output is correct |
107 |
Correct |
28 ms |
5880 KB |
Output is correct |
108 |
Correct |
38 ms |
7660 KB |
Output is correct |
109 |
Correct |
4 ms |
2688 KB |
Output is correct |
110 |
Correct |
53 ms |
8184 KB |
Output is correct |
111 |
Correct |
53 ms |
9208 KB |
Output is correct |
112 |
Correct |
8 ms |
2816 KB |
Output is correct |
113 |
Correct |
91 ms |
13748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
5116 KB |
Output is correct |
2 |
Incorrect |
22 ms |
5120 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
10232 KB |
Output is correct |
2 |
Correct |
59 ms |
9968 KB |
Output is correct |
3 |
Correct |
40 ms |
8824 KB |
Output is correct |
4 |
Correct |
13 ms |
3712 KB |
Output is correct |
5 |
Correct |
10 ms |
3328 KB |
Output is correct |
6 |
Correct |
17 ms |
4352 KB |
Output is correct |
7 |
Correct |
4 ms |
2688 KB |
Output is correct |
8 |
Correct |
29 ms |
5996 KB |
Output is correct |
9 |
Correct |
42 ms |
7672 KB |
Output is correct |
10 |
Correct |
4 ms |
2816 KB |
Output is correct |
11 |
Correct |
48 ms |
8184 KB |
Output is correct |
12 |
Correct |
55 ms |
9212 KB |
Output is correct |
13 |
Correct |
5 ms |
2816 KB |
Output is correct |
14 |
Correct |
3 ms |
2688 KB |
Output is correct |
15 |
Correct |
4 ms |
2812 KB |
Output is correct |
16 |
Correct |
5 ms |
2788 KB |
Output is correct |
17 |
Correct |
4 ms |
2688 KB |
Output is correct |
18 |
Correct |
4 ms |
2816 KB |
Output is correct |
19 |
Correct |
5 ms |
2816 KB |
Output is correct |
20 |
Incorrect |
4 ms |
2688 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
10232 KB |
Output is correct |
2 |
Correct |
59 ms |
9968 KB |
Output is correct |
3 |
Correct |
40 ms |
8824 KB |
Output is correct |
4 |
Correct |
13 ms |
3712 KB |
Output is correct |
5 |
Correct |
10 ms |
3328 KB |
Output is correct |
6 |
Correct |
17 ms |
4352 KB |
Output is correct |
7 |
Correct |
4 ms |
2688 KB |
Output is correct |
8 |
Correct |
29 ms |
5996 KB |
Output is correct |
9 |
Correct |
42 ms |
7672 KB |
Output is correct |
10 |
Correct |
4 ms |
2816 KB |
Output is correct |
11 |
Correct |
48 ms |
8184 KB |
Output is correct |
12 |
Correct |
55 ms |
9212 KB |
Output is correct |
13 |
Correct |
5 ms |
2816 KB |
Output is correct |
14 |
Correct |
3 ms |
2688 KB |
Output is correct |
15 |
Correct |
3 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 |
4 ms |
2688 KB |
Output is correct |
20 |
Correct |
3 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 |
4 ms |
2688 KB |
Output is correct |
25 |
Correct |
4 ms |
2688 KB |
Output is correct |
26 |
Correct |
3 ms |
2688 KB |
Output is correct |
27 |
Correct |
3 ms |
2688 KB |
Output is correct |
28 |
Correct |
3 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 |
2688 KB |
Output is correct |
34 |
Correct |
4 ms |
2688 KB |
Output is correct |
35 |
Correct |
3 ms |
2688 KB |
Output is correct |
36 |
Correct |
4 ms |
2688 KB |
Output is correct |
37 |
Correct |
5 ms |
2688 KB |
Output is correct |
38 |
Correct |
4 ms |
2688 KB |
Output is correct |
39 |
Correct |
58 ms |
10420 KB |
Output is correct |
40 |
Correct |
55 ms |
9976 KB |
Output is correct |
41 |
Correct |
38 ms |
8824 KB |
Output is correct |
42 |
Correct |
10 ms |
3840 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 |
2816 KB |
Output is correct |
51 |
Correct |
3 ms |
2688 KB |
Output is correct |
52 |
Correct |
4 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 |
72 ms |
8440 KB |
Output is correct |
58 |
Correct |
87 ms |
8444 KB |
Output is correct |
59 |
Correct |
73 ms |
8264 KB |
Output is correct |
60 |
Correct |
83 ms |
8312 KB |
Output is correct |
61 |
Correct |
68 ms |
8312 KB |
Output is correct |
62 |
Correct |
82 ms |
8312 KB |
Output is correct |
63 |
Correct |
64 ms |
8184 KB |
Output is correct |
64 |
Correct |
92 ms |
8056 KB |
Output is correct |
65 |
Correct |
67 ms |
8056 KB |
Output is correct |
66 |
Correct |
90 ms |
8056 KB |
Output is correct |
67 |
Correct |
76 ms |
8312 KB |
Output is correct |
68 |
Correct |
77 ms |
8312 KB |
Output is correct |
69 |
Correct |
76 ms |
8312 KB |
Output is correct |
70 |
Correct |
95 ms |
8316 KB |
Output is correct |
71 |
Correct |
3 ms |
2688 KB |
Output is correct |
72 |
Correct |
4 ms |
2816 KB |
Output is correct |
73 |
Correct |
5 ms |
2816 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 |
2816 KB |
Output is correct |
77 |
Correct |
5 ms |
2816 KB |
Output is correct |
78 |
Correct |
7 ms |
2816 KB |
Output is correct |
79 |
Correct |
5 ms |
2816 KB |
Output is correct |
80 |
Correct |
142 ms |
8312 KB |
Output is correct |
81 |
Correct |
78 ms |
8312 KB |
Output is correct |
82 |
Correct |
87 ms |
8184 KB |
Output is correct |
83 |
Correct |
64 ms |
8312 KB |
Output is correct |
84 |
Correct |
6 ms |
2816 KB |
Output is correct |
85 |
Correct |
4 ms |
2788 KB |
Output is correct |
86 |
Correct |
5 ms |
2816 KB |
Output is correct |
87 |
Correct |
5 ms |
2816 KB |
Output is correct |
88 |
Correct |
5 ms |
2816 KB |
Output is correct |
89 |
Correct |
5 ms |
2788 KB |
Output is correct |
90 |
Correct |
6 ms |
2816 KB |
Output is correct |
91 |
Correct |
5 ms |
2816 KB |
Output is correct |
92 |
Correct |
5 ms |
2816 KB |
Output is correct |
93 |
Correct |
5 ms |
2816 KB |
Output is correct |
94 |
Correct |
4 ms |
2688 KB |
Output is correct |
95 |
Correct |
3 ms |
2688 KB |
Output is correct |
96 |
Correct |
4 ms |
2688 KB |
Output is correct |
97 |
Correct |
3 ms |
2688 KB |
Output is correct |
98 |
Correct |
5 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 |
2660 KB |
Output is correct |
104 |
Correct |
9 ms |
3328 KB |
Output is correct |
105 |
Correct |
15 ms |
4352 KB |
Output is correct |
106 |
Correct |
3 ms |
2688 KB |
Output is correct |
107 |
Correct |
28 ms |
5880 KB |
Output is correct |
108 |
Correct |
38 ms |
7660 KB |
Output is correct |
109 |
Correct |
4 ms |
2688 KB |
Output is correct |
110 |
Correct |
53 ms |
8184 KB |
Output is correct |
111 |
Correct |
53 ms |
9208 KB |
Output is correct |
112 |
Correct |
8 ms |
2816 KB |
Output is correct |
113 |
Correct |
91 ms |
13748 KB |
Output is correct |
114 |
Correct |
32 ms |
5116 KB |
Output is correct |
115 |
Incorrect |
22 ms |
5120 KB |
Output isn't correct |
116 |
Halted |
0 ms |
0 KB |
- |