#include<bits/stdc++.h>
#define fi first
#define se second
#include "dreaming.h"
using namespace std;
vector<pair<int,int> > adj[1000000];
pair <int,int> par[100000];
int n,m,component, dis[100000],mx,start,end1,timer,tin[100000],tout[100000],ans ,comp[100000] , day;
int vis[100000];
void dfs (int v,int p,int val) {
if (dis[v] > mx) {
mx = dis[v];
start = v;
}
par[v] = {p,val};
for (auto i : adj[v]) {
if (i.fi != p) {
dis[i.fi] = dis[v] + i.se;
vis[i.fi] = vis[v];
dfs (i.fi, v, i.se);
}
}
}
void get_mid (int a,int b) {
// b is root
int distance = dis[a],down = 0;
ans = max (ans, distance);
comp[component] = distance;
int mn = INT_MAX;
while (a != b) {
down += par[a].se;
distance -= par[a].se;
mn = min (mn , max (down,distance));
a = par[a].fi;
}
if (mn == INT_MAX)
comp[component] = 0;
else comp[component] = mn;
}
int make_components() {
for (int i = 0; i < n; i++) {
if (!vis[i]) {
mx = INT_MIN;
component++;
vis[i] = (i ? vis[i-1] + 1 : 1);
dfs(i,-1,0);
end1 = start;
dis[start] = 0;
mx = INT_MIN;
dfs (end1,-1,0);
get_mid(start,end1);
}
}
int mn = comp[1],in = 1;
sort (comp + 1, comp + component + 1);
if (component == 1) return ans;
if (component == 2) {
return max (ans, comp[1] + comp[2] + day);
}
return max (ans, day*2 + comp[component - 1] + comp [component]);
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
n = N; m = M; day = L;
for (int i = 0; i < m; i++) {
adj[A[i]].push_back( { B[i], T[i] });
adj[B[i]].push_back( { A[i], T[i] });
}
return make_components();
} /*
main () {
int N,M,L;
cin >> N >> M >> L;
int A[M],B[M],T[M];
for (int i = 0; i < M; i++)
cin >> A[i] >> B[i] >> T[i] ;
cout << travelTime(N, M, L, A, B, T);
} */
Compilation message
dreaming.cpp: In function 'int make_components()':
dreaming.cpp:56:6: warning: unused variable 'mn' [-Wunused-variable]
int mn = comp[1],in = 1;
^~
dreaming.cpp:56:19: warning: unused variable 'in' [-Wunused-variable]
int mn = comp[1],in = 1;
^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
34680 KB |
Output is correct |
2 |
Correct |
75 ms |
34684 KB |
Output is correct |
3 |
Correct |
54 ms |
31096 KB |
Output is correct |
4 |
Correct |
25 ms |
25472 KB |
Output is correct |
5 |
Correct |
24 ms |
24832 KB |
Output is correct |
6 |
Correct |
31 ms |
26240 KB |
Output is correct |
7 |
Correct |
18 ms |
23808 KB |
Output is correct |
8 |
Correct |
45 ms |
27904 KB |
Output is correct |
9 |
Correct |
53 ms |
29304 KB |
Output is correct |
10 |
Correct |
20 ms |
23936 KB |
Output is correct |
11 |
Correct |
76 ms |
31352 KB |
Output is correct |
12 |
Correct |
86 ms |
32888 KB |
Output is correct |
13 |
Correct |
18 ms |
23936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
34680 KB |
Output is correct |
2 |
Correct |
75 ms |
34684 KB |
Output is correct |
3 |
Correct |
54 ms |
31096 KB |
Output is correct |
4 |
Correct |
25 ms |
25472 KB |
Output is correct |
5 |
Correct |
24 ms |
24832 KB |
Output is correct |
6 |
Correct |
31 ms |
26240 KB |
Output is correct |
7 |
Correct |
18 ms |
23808 KB |
Output is correct |
8 |
Correct |
45 ms |
27904 KB |
Output is correct |
9 |
Correct |
53 ms |
29304 KB |
Output is correct |
10 |
Correct |
20 ms |
23936 KB |
Output is correct |
11 |
Correct |
76 ms |
31352 KB |
Output is correct |
12 |
Correct |
86 ms |
32888 KB |
Output is correct |
13 |
Correct |
18 ms |
23936 KB |
Output is correct |
14 |
Correct |
18 ms |
23808 KB |
Output is correct |
15 |
Correct |
17 ms |
23808 KB |
Output is correct |
16 |
Correct |
17 ms |
23808 KB |
Output is correct |
17 |
Correct |
18 ms |
23808 KB |
Output is correct |
18 |
Correct |
23 ms |
23808 KB |
Output is correct |
19 |
Correct |
19 ms |
23808 KB |
Output is correct |
20 |
Correct |
18 ms |
23808 KB |
Output is correct |
21 |
Correct |
18 ms |
23808 KB |
Output is correct |
22 |
Correct |
20 ms |
23808 KB |
Output is correct |
23 |
Correct |
18 ms |
23808 KB |
Output is correct |
24 |
Correct |
18 ms |
23808 KB |
Output is correct |
25 |
Correct |
18 ms |
23808 KB |
Output is correct |
26 |
Correct |
18 ms |
23808 KB |
Output is correct |
27 |
Correct |
18 ms |
23808 KB |
Output is correct |
28 |
Correct |
18 ms |
23808 KB |
Output is correct |
29 |
Correct |
19 ms |
23808 KB |
Output is correct |
30 |
Correct |
18 ms |
23808 KB |
Output is correct |
31 |
Correct |
20 ms |
23808 KB |
Output is correct |
32 |
Correct |
18 ms |
23808 KB |
Output is correct |
33 |
Correct |
17 ms |
23808 KB |
Output is correct |
34 |
Correct |
18 ms |
23808 KB |
Output is correct |
35 |
Correct |
18 ms |
23808 KB |
Output is correct |
36 |
Correct |
18 ms |
23808 KB |
Output is correct |
37 |
Correct |
18 ms |
23808 KB |
Output is correct |
38 |
Correct |
20 ms |
23808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
34680 KB |
Output is correct |
2 |
Correct |
75 ms |
34684 KB |
Output is correct |
3 |
Correct |
54 ms |
31096 KB |
Output is correct |
4 |
Correct |
25 ms |
25472 KB |
Output is correct |
5 |
Correct |
24 ms |
24832 KB |
Output is correct |
6 |
Correct |
31 ms |
26240 KB |
Output is correct |
7 |
Correct |
18 ms |
23808 KB |
Output is correct |
8 |
Correct |
45 ms |
27904 KB |
Output is correct |
9 |
Correct |
53 ms |
29304 KB |
Output is correct |
10 |
Correct |
20 ms |
23936 KB |
Output is correct |
11 |
Correct |
76 ms |
31352 KB |
Output is correct |
12 |
Correct |
86 ms |
32888 KB |
Output is correct |
13 |
Correct |
18 ms |
23936 KB |
Output is correct |
14 |
Correct |
18 ms |
23808 KB |
Output is correct |
15 |
Correct |
17 ms |
23808 KB |
Output is correct |
16 |
Correct |
17 ms |
23808 KB |
Output is correct |
17 |
Correct |
18 ms |
23808 KB |
Output is correct |
18 |
Correct |
23 ms |
23808 KB |
Output is correct |
19 |
Correct |
19 ms |
23808 KB |
Output is correct |
20 |
Correct |
18 ms |
23808 KB |
Output is correct |
21 |
Correct |
18 ms |
23808 KB |
Output is correct |
22 |
Correct |
20 ms |
23808 KB |
Output is correct |
23 |
Correct |
18 ms |
23808 KB |
Output is correct |
24 |
Correct |
18 ms |
23808 KB |
Output is correct |
25 |
Correct |
18 ms |
23808 KB |
Output is correct |
26 |
Correct |
18 ms |
23808 KB |
Output is correct |
27 |
Correct |
18 ms |
23808 KB |
Output is correct |
28 |
Correct |
18 ms |
23808 KB |
Output is correct |
29 |
Correct |
19 ms |
23808 KB |
Output is correct |
30 |
Correct |
18 ms |
23808 KB |
Output is correct |
31 |
Correct |
20 ms |
23808 KB |
Output is correct |
32 |
Correct |
18 ms |
23808 KB |
Output is correct |
33 |
Correct |
17 ms |
23808 KB |
Output is correct |
34 |
Correct |
18 ms |
23808 KB |
Output is correct |
35 |
Correct |
18 ms |
23808 KB |
Output is correct |
36 |
Correct |
18 ms |
23808 KB |
Output is correct |
37 |
Correct |
18 ms |
23808 KB |
Output is correct |
38 |
Correct |
20 ms |
23808 KB |
Output is correct |
39 |
Correct |
79 ms |
34680 KB |
Output is correct |
40 |
Correct |
73 ms |
34680 KB |
Output is correct |
41 |
Correct |
55 ms |
31096 KB |
Output is correct |
42 |
Correct |
26 ms |
25468 KB |
Output is correct |
43 |
Correct |
18 ms |
23808 KB |
Output is correct |
44 |
Correct |
18 ms |
23808 KB |
Output is correct |
45 |
Correct |
18 ms |
23808 KB |
Output is correct |
46 |
Correct |
17 ms |
23808 KB |
Output is correct |
47 |
Correct |
18 ms |
23808 KB |
Output is correct |
48 |
Correct |
18 ms |
23808 KB |
Output is correct |
49 |
Correct |
19 ms |
23808 KB |
Output is correct |
50 |
Correct |
18 ms |
23808 KB |
Output is correct |
51 |
Correct |
18 ms |
23936 KB |
Output is correct |
52 |
Correct |
18 ms |
23808 KB |
Output is correct |
53 |
Correct |
18 ms |
23808 KB |
Output is correct |
54 |
Correct |
19 ms |
23936 KB |
Output is correct |
55 |
Correct |
18 ms |
23808 KB |
Output is correct |
56 |
Correct |
18 ms |
23808 KB |
Output is correct |
57 |
Correct |
105 ms |
31864 KB |
Output is correct |
58 |
Correct |
107 ms |
31864 KB |
Output is correct |
59 |
Correct |
95 ms |
31864 KB |
Output is correct |
60 |
Correct |
97 ms |
31864 KB |
Output is correct |
61 |
Correct |
99 ms |
31900 KB |
Output is correct |
62 |
Correct |
104 ms |
31864 KB |
Output is correct |
63 |
Correct |
99 ms |
31608 KB |
Output is correct |
64 |
Correct |
94 ms |
31736 KB |
Output is correct |
65 |
Correct |
102 ms |
31908 KB |
Output is correct |
66 |
Correct |
94 ms |
31864 KB |
Output is correct |
67 |
Correct |
108 ms |
31736 KB |
Output is correct |
68 |
Correct |
108 ms |
31736 KB |
Output is correct |
69 |
Correct |
113 ms |
32120 KB |
Output is correct |
70 |
Correct |
112 ms |
32120 KB |
Output is correct |
71 |
Correct |
18 ms |
23808 KB |
Output is correct |
72 |
Correct |
20 ms |
24064 KB |
Output is correct |
73 |
Correct |
20 ms |
24064 KB |
Output is correct |
74 |
Correct |
20 ms |
24064 KB |
Output is correct |
75 |
Correct |
19 ms |
24192 KB |
Output is correct |
76 |
Correct |
20 ms |
24064 KB |
Output is correct |
77 |
Correct |
19 ms |
24064 KB |
Output is correct |
78 |
Correct |
20 ms |
24064 KB |
Output is correct |
79 |
Correct |
19 ms |
24064 KB |
Output is correct |
80 |
Correct |
109 ms |
31736 KB |
Output is correct |
81 |
Correct |
107 ms |
31736 KB |
Output is correct |
82 |
Correct |
105 ms |
31892 KB |
Output is correct |
83 |
Correct |
90 ms |
31864 KB |
Output is correct |
84 |
Correct |
18 ms |
24064 KB |
Output is correct |
85 |
Correct |
19 ms |
24064 KB |
Output is correct |
86 |
Correct |
19 ms |
24064 KB |
Output is correct |
87 |
Correct |
20 ms |
24064 KB |
Output is correct |
88 |
Correct |
19 ms |
24064 KB |
Output is correct |
89 |
Correct |
19 ms |
24064 KB |
Output is correct |
90 |
Correct |
19 ms |
24064 KB |
Output is correct |
91 |
Correct |
20 ms |
24064 KB |
Output is correct |
92 |
Correct |
19 ms |
24064 KB |
Output is correct |
93 |
Correct |
20 ms |
24064 KB |
Output is correct |
94 |
Correct |
18 ms |
23808 KB |
Output is correct |
95 |
Correct |
18 ms |
23808 KB |
Output is correct |
96 |
Correct |
18 ms |
23808 KB |
Output is correct |
97 |
Correct |
18 ms |
23808 KB |
Output is correct |
98 |
Correct |
18 ms |
23808 KB |
Output is correct |
99 |
Correct |
18 ms |
23808 KB |
Output is correct |
100 |
Correct |
18 ms |
23912 KB |
Output is correct |
101 |
Correct |
18 ms |
23808 KB |
Output is correct |
102 |
Correct |
18 ms |
23808 KB |
Output is correct |
103 |
Correct |
18 ms |
23936 KB |
Output is correct |
104 |
Correct |
24 ms |
24832 KB |
Output is correct |
105 |
Correct |
33 ms |
26368 KB |
Output is correct |
106 |
Correct |
19 ms |
23808 KB |
Output is correct |
107 |
Correct |
45 ms |
27904 KB |
Output is correct |
108 |
Correct |
53 ms |
29304 KB |
Output is correct |
109 |
Correct |
18 ms |
23936 KB |
Output is correct |
110 |
Correct |
73 ms |
31352 KB |
Output is correct |
111 |
Correct |
93 ms |
32888 KB |
Output is correct |
112 |
Correct |
18 ms |
23936 KB |
Output is correct |
113 |
Correct |
125 ms |
35960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
43 ms |
28280 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
34680 KB |
Output is correct |
2 |
Correct |
75 ms |
34684 KB |
Output is correct |
3 |
Correct |
54 ms |
31096 KB |
Output is correct |
4 |
Correct |
25 ms |
25472 KB |
Output is correct |
5 |
Correct |
24 ms |
24832 KB |
Output is correct |
6 |
Correct |
31 ms |
26240 KB |
Output is correct |
7 |
Correct |
18 ms |
23808 KB |
Output is correct |
8 |
Correct |
45 ms |
27904 KB |
Output is correct |
9 |
Correct |
53 ms |
29304 KB |
Output is correct |
10 |
Correct |
20 ms |
23936 KB |
Output is correct |
11 |
Correct |
76 ms |
31352 KB |
Output is correct |
12 |
Correct |
86 ms |
32888 KB |
Output is correct |
13 |
Correct |
18 ms |
23936 KB |
Output is correct |
14 |
Correct |
18 ms |
23936 KB |
Output is correct |
15 |
Correct |
19 ms |
24064 KB |
Output is correct |
16 |
Correct |
20 ms |
24064 KB |
Output is correct |
17 |
Incorrect |
19 ms |
23936 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
34680 KB |
Output is correct |
2 |
Correct |
75 ms |
34684 KB |
Output is correct |
3 |
Correct |
54 ms |
31096 KB |
Output is correct |
4 |
Correct |
25 ms |
25472 KB |
Output is correct |
5 |
Correct |
24 ms |
24832 KB |
Output is correct |
6 |
Correct |
31 ms |
26240 KB |
Output is correct |
7 |
Correct |
18 ms |
23808 KB |
Output is correct |
8 |
Correct |
45 ms |
27904 KB |
Output is correct |
9 |
Correct |
53 ms |
29304 KB |
Output is correct |
10 |
Correct |
20 ms |
23936 KB |
Output is correct |
11 |
Correct |
76 ms |
31352 KB |
Output is correct |
12 |
Correct |
86 ms |
32888 KB |
Output is correct |
13 |
Correct |
18 ms |
23936 KB |
Output is correct |
14 |
Correct |
18 ms |
23808 KB |
Output is correct |
15 |
Correct |
17 ms |
23808 KB |
Output is correct |
16 |
Correct |
17 ms |
23808 KB |
Output is correct |
17 |
Correct |
18 ms |
23808 KB |
Output is correct |
18 |
Correct |
23 ms |
23808 KB |
Output is correct |
19 |
Correct |
19 ms |
23808 KB |
Output is correct |
20 |
Correct |
18 ms |
23808 KB |
Output is correct |
21 |
Correct |
18 ms |
23808 KB |
Output is correct |
22 |
Correct |
20 ms |
23808 KB |
Output is correct |
23 |
Correct |
18 ms |
23808 KB |
Output is correct |
24 |
Correct |
18 ms |
23808 KB |
Output is correct |
25 |
Correct |
18 ms |
23808 KB |
Output is correct |
26 |
Correct |
18 ms |
23808 KB |
Output is correct |
27 |
Correct |
18 ms |
23808 KB |
Output is correct |
28 |
Correct |
18 ms |
23808 KB |
Output is correct |
29 |
Correct |
19 ms |
23808 KB |
Output is correct |
30 |
Correct |
18 ms |
23808 KB |
Output is correct |
31 |
Correct |
20 ms |
23808 KB |
Output is correct |
32 |
Correct |
18 ms |
23808 KB |
Output is correct |
33 |
Correct |
17 ms |
23808 KB |
Output is correct |
34 |
Correct |
18 ms |
23808 KB |
Output is correct |
35 |
Correct |
18 ms |
23808 KB |
Output is correct |
36 |
Correct |
18 ms |
23808 KB |
Output is correct |
37 |
Correct |
18 ms |
23808 KB |
Output is correct |
38 |
Correct |
20 ms |
23808 KB |
Output is correct |
39 |
Correct |
79 ms |
34680 KB |
Output is correct |
40 |
Correct |
73 ms |
34680 KB |
Output is correct |
41 |
Correct |
55 ms |
31096 KB |
Output is correct |
42 |
Correct |
26 ms |
25468 KB |
Output is correct |
43 |
Correct |
18 ms |
23808 KB |
Output is correct |
44 |
Correct |
18 ms |
23808 KB |
Output is correct |
45 |
Correct |
18 ms |
23808 KB |
Output is correct |
46 |
Correct |
17 ms |
23808 KB |
Output is correct |
47 |
Correct |
18 ms |
23808 KB |
Output is correct |
48 |
Correct |
18 ms |
23808 KB |
Output is correct |
49 |
Correct |
19 ms |
23808 KB |
Output is correct |
50 |
Correct |
18 ms |
23808 KB |
Output is correct |
51 |
Correct |
18 ms |
23936 KB |
Output is correct |
52 |
Correct |
18 ms |
23808 KB |
Output is correct |
53 |
Correct |
18 ms |
23808 KB |
Output is correct |
54 |
Correct |
19 ms |
23936 KB |
Output is correct |
55 |
Correct |
18 ms |
23808 KB |
Output is correct |
56 |
Correct |
18 ms |
23808 KB |
Output is correct |
57 |
Correct |
105 ms |
31864 KB |
Output is correct |
58 |
Correct |
107 ms |
31864 KB |
Output is correct |
59 |
Correct |
95 ms |
31864 KB |
Output is correct |
60 |
Correct |
97 ms |
31864 KB |
Output is correct |
61 |
Correct |
99 ms |
31900 KB |
Output is correct |
62 |
Correct |
104 ms |
31864 KB |
Output is correct |
63 |
Correct |
99 ms |
31608 KB |
Output is correct |
64 |
Correct |
94 ms |
31736 KB |
Output is correct |
65 |
Correct |
102 ms |
31908 KB |
Output is correct |
66 |
Correct |
94 ms |
31864 KB |
Output is correct |
67 |
Correct |
108 ms |
31736 KB |
Output is correct |
68 |
Correct |
108 ms |
31736 KB |
Output is correct |
69 |
Correct |
113 ms |
32120 KB |
Output is correct |
70 |
Correct |
112 ms |
32120 KB |
Output is correct |
71 |
Correct |
18 ms |
23808 KB |
Output is correct |
72 |
Correct |
20 ms |
24064 KB |
Output is correct |
73 |
Correct |
20 ms |
24064 KB |
Output is correct |
74 |
Correct |
20 ms |
24064 KB |
Output is correct |
75 |
Correct |
19 ms |
24192 KB |
Output is correct |
76 |
Correct |
20 ms |
24064 KB |
Output is correct |
77 |
Correct |
19 ms |
24064 KB |
Output is correct |
78 |
Correct |
20 ms |
24064 KB |
Output is correct |
79 |
Correct |
19 ms |
24064 KB |
Output is correct |
80 |
Correct |
109 ms |
31736 KB |
Output is correct |
81 |
Correct |
107 ms |
31736 KB |
Output is correct |
82 |
Correct |
105 ms |
31892 KB |
Output is correct |
83 |
Correct |
90 ms |
31864 KB |
Output is correct |
84 |
Correct |
18 ms |
24064 KB |
Output is correct |
85 |
Correct |
19 ms |
24064 KB |
Output is correct |
86 |
Correct |
19 ms |
24064 KB |
Output is correct |
87 |
Correct |
20 ms |
24064 KB |
Output is correct |
88 |
Correct |
19 ms |
24064 KB |
Output is correct |
89 |
Correct |
19 ms |
24064 KB |
Output is correct |
90 |
Correct |
19 ms |
24064 KB |
Output is correct |
91 |
Correct |
20 ms |
24064 KB |
Output is correct |
92 |
Correct |
19 ms |
24064 KB |
Output is correct |
93 |
Correct |
20 ms |
24064 KB |
Output is correct |
94 |
Correct |
18 ms |
23808 KB |
Output is correct |
95 |
Correct |
18 ms |
23808 KB |
Output is correct |
96 |
Correct |
18 ms |
23808 KB |
Output is correct |
97 |
Correct |
18 ms |
23808 KB |
Output is correct |
98 |
Correct |
18 ms |
23808 KB |
Output is correct |
99 |
Correct |
18 ms |
23808 KB |
Output is correct |
100 |
Correct |
18 ms |
23912 KB |
Output is correct |
101 |
Correct |
18 ms |
23808 KB |
Output is correct |
102 |
Correct |
18 ms |
23808 KB |
Output is correct |
103 |
Correct |
18 ms |
23936 KB |
Output is correct |
104 |
Correct |
24 ms |
24832 KB |
Output is correct |
105 |
Correct |
33 ms |
26368 KB |
Output is correct |
106 |
Correct |
19 ms |
23808 KB |
Output is correct |
107 |
Correct |
45 ms |
27904 KB |
Output is correct |
108 |
Correct |
53 ms |
29304 KB |
Output is correct |
109 |
Correct |
18 ms |
23936 KB |
Output is correct |
110 |
Correct |
73 ms |
31352 KB |
Output is correct |
111 |
Correct |
93 ms |
32888 KB |
Output is correct |
112 |
Correct |
18 ms |
23936 KB |
Output is correct |
113 |
Correct |
125 ms |
35960 KB |
Output is correct |
114 |
Incorrect |
43 ms |
28280 KB |
Output isn't correct |
115 |
Halted |
0 ms |
0 KB |
- |