#include <bits/stdc++.h>
#include "dreaming.h"
#define f first
#define s second
using namespace std;
const int maxn = 1e5 + 69;
vector<pair<int, int>> g[maxn];
vector<int> vis(maxn);
vector<int> d(maxn), par(maxn);
vector<int> t;
void dfs(int v, int p) {
vis[v] = true;
t.push_back(v);
par[v] = p;
for(auto u : g[v]) {
if(u.f != p) {
d[u.f] = d[v] + u.s;
dfs(u.f, v);
}
}
}
int find_minmax(vector<int> &v, int dija) {
//v->cvorovi koji cine dijametar stabla
int mn = 1e9, res = -1;
for(auto x : v) {
int y = max(d[x], dija - d[x]);
if(mn >= y) {
mn = y;
res = x;
}
}
return res;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
for(int i = 0;i < M;i++) {
g[A[i]].push_back({B[i], T[i]});
g[B[i]].push_back({A[i], T[i]});
}
vector<int> r;
for(int i = 0;i < N;i++) {
if(!vis[i]) {
t.clear();
dfs(i, -1);
int s, mx = 0;
for(auto x : t) {
if(d[x] >= mx) {
mx = d[x];
s = x;
}
}
t.clear();
d[s] = 0;
dfs(s, -1);
mx = 0;
for(auto x : t) {
if(d[x] >= mx) {
mx = d[x];
s = x;
}
}
vector<int> c;
while(s != -1) {
c.push_back(s);
s = par[s];
}
r.push_back(find_minmax(c, mx));
}
}
for(int i = 1;i < (int)r.size();i++) {
g[r[i]].push_back({r[i - 1], L});
g[r[i - 1]].push_back({r[i], L});
}
dfs(0, -1);
int s, mx = 0;
for(auto x : t) {
if(d[x] >= mx) {
mx = d[x];
s = x;
}
}
t.clear();
d[s] = 0;
dfs(s, -1);
int ans = 0;
for(int i = 0;i < N;i++)
ans = max(ans, d[i]);
return ans;
}
//
// int main()
// {
// ios_base::sync_with_stdio(false);
// cin.tie(0);
// cout.tie(0);
// int tt = 1;
// //cin >> tt;
// while(tt--) {
// 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);
// }
// return 0;
// }
Compilation message
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:87:5: warning: 'second' may be used uninitialized in this function [-Wmaybe-uninitialized]
87 | dfs(s, -1);
| ~~~^~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
13076 KB |
Output is correct |
2 |
Correct |
36 ms |
13128 KB |
Output is correct |
3 |
Correct |
25 ms |
9844 KB |
Output is correct |
4 |
Correct |
8 ms |
5204 KB |
Output is correct |
5 |
Correct |
6 ms |
4636 KB |
Output is correct |
6 |
Correct |
11 ms |
5804 KB |
Output is correct |
7 |
Correct |
2 ms |
3796 KB |
Output is correct |
8 |
Correct |
20 ms |
7092 KB |
Output is correct |
9 |
Correct |
33 ms |
8552 KB |
Output is correct |
10 |
Correct |
2 ms |
3796 KB |
Output is correct |
11 |
Correct |
34 ms |
9712 KB |
Output is correct |
12 |
Correct |
41 ms |
11468 KB |
Output is correct |
13 |
Correct |
2 ms |
3924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3796 KB |
Output is correct |
2 |
Correct |
2 ms |
3796 KB |
Output is correct |
3 |
Correct |
2 ms |
3796 KB |
Output is correct |
4 |
Correct |
2 ms |
3796 KB |
Output is correct |
5 |
Correct |
2 ms |
3796 KB |
Output is correct |
6 |
Correct |
2 ms |
3796 KB |
Output is correct |
7 |
Correct |
2 ms |
3848 KB |
Output is correct |
8 |
Correct |
2 ms |
3796 KB |
Output is correct |
9 |
Correct |
2 ms |
3796 KB |
Output is correct |
10 |
Correct |
2 ms |
3796 KB |
Output is correct |
11 |
Correct |
2 ms |
3848 KB |
Output is correct |
12 |
Correct |
2 ms |
3796 KB |
Output is correct |
13 |
Correct |
2 ms |
3796 KB |
Output is correct |
14 |
Correct |
2 ms |
3796 KB |
Output is correct |
15 |
Correct |
2 ms |
3796 KB |
Output is correct |
16 |
Correct |
2 ms |
3852 KB |
Output is correct |
17 |
Correct |
2 ms |
3796 KB |
Output is correct |
18 |
Correct |
2 ms |
3796 KB |
Output is correct |
19 |
Correct |
3 ms |
3796 KB |
Output is correct |
20 |
Correct |
2 ms |
3852 KB |
Output is correct |
21 |
Correct |
2 ms |
3796 KB |
Output is correct |
22 |
Correct |
2 ms |
3844 KB |
Output is correct |
23 |
Correct |
2 ms |
3796 KB |
Output is correct |
24 |
Correct |
2 ms |
3796 KB |
Output is correct |
25 |
Correct |
2 ms |
3796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
13076 KB |
Output is correct |
2 |
Correct |
36 ms |
13128 KB |
Output is correct |
3 |
Correct |
25 ms |
9844 KB |
Output is correct |
4 |
Correct |
8 ms |
5204 KB |
Output is correct |
5 |
Correct |
6 ms |
4636 KB |
Output is correct |
6 |
Correct |
11 ms |
5804 KB |
Output is correct |
7 |
Correct |
2 ms |
3796 KB |
Output is correct |
8 |
Correct |
20 ms |
7092 KB |
Output is correct |
9 |
Correct |
33 ms |
8552 KB |
Output is correct |
10 |
Correct |
2 ms |
3796 KB |
Output is correct |
11 |
Correct |
34 ms |
9712 KB |
Output is correct |
12 |
Correct |
41 ms |
11468 KB |
Output is correct |
13 |
Correct |
2 ms |
3924 KB |
Output is correct |
14 |
Correct |
2 ms |
3796 KB |
Output is correct |
15 |
Correct |
2 ms |
3796 KB |
Output is correct |
16 |
Correct |
2 ms |
3796 KB |
Output is correct |
17 |
Correct |
2 ms |
3796 KB |
Output is correct |
18 |
Correct |
2 ms |
3796 KB |
Output is correct |
19 |
Correct |
2 ms |
3796 KB |
Output is correct |
20 |
Correct |
2 ms |
3848 KB |
Output is correct |
21 |
Correct |
2 ms |
3796 KB |
Output is correct |
22 |
Correct |
2 ms |
3796 KB |
Output is correct |
23 |
Correct |
2 ms |
3796 KB |
Output is correct |
24 |
Correct |
2 ms |
3848 KB |
Output is correct |
25 |
Correct |
2 ms |
3796 KB |
Output is correct |
26 |
Correct |
2 ms |
3796 KB |
Output is correct |
27 |
Correct |
2 ms |
3796 KB |
Output is correct |
28 |
Correct |
2 ms |
3796 KB |
Output is correct |
29 |
Correct |
2 ms |
3852 KB |
Output is correct |
30 |
Correct |
2 ms |
3796 KB |
Output is correct |
31 |
Correct |
2 ms |
3796 KB |
Output is correct |
32 |
Correct |
3 ms |
3796 KB |
Output is correct |
33 |
Correct |
2 ms |
3852 KB |
Output is correct |
34 |
Correct |
2 ms |
3796 KB |
Output is correct |
35 |
Correct |
2 ms |
3844 KB |
Output is correct |
36 |
Correct |
2 ms |
3796 KB |
Output is correct |
37 |
Correct |
2 ms |
3796 KB |
Output is correct |
38 |
Correct |
2 ms |
3796 KB |
Output is correct |
39 |
Correct |
51 ms |
14412 KB |
Output is correct |
40 |
Correct |
42 ms |
14280 KB |
Output is correct |
41 |
Correct |
25 ms |
10752 KB |
Output is correct |
42 |
Correct |
7 ms |
5332 KB |
Output is correct |
43 |
Correct |
2 ms |
3796 KB |
Output is correct |
44 |
Correct |
2 ms |
3796 KB |
Output is correct |
45 |
Correct |
2 ms |
3796 KB |
Output is correct |
46 |
Correct |
2 ms |
3796 KB |
Output is correct |
47 |
Correct |
2 ms |
3796 KB |
Output is correct |
48 |
Correct |
2 ms |
3796 KB |
Output is correct |
49 |
Correct |
2 ms |
3796 KB |
Output is correct |
50 |
Correct |
2 ms |
3796 KB |
Output is correct |
51 |
Correct |
2 ms |
3796 KB |
Output is correct |
52 |
Correct |
3 ms |
3796 KB |
Output is correct |
53 |
Correct |
2 ms |
3848 KB |
Output is correct |
54 |
Correct |
2 ms |
3796 KB |
Output is correct |
55 |
Correct |
2 ms |
3796 KB |
Output is correct |
56 |
Correct |
2 ms |
3796 KB |
Output is correct |
57 |
Correct |
45 ms |
10888 KB |
Output is correct |
58 |
Correct |
61 ms |
11500 KB |
Output is correct |
59 |
Correct |
47 ms |
10848 KB |
Output is correct |
60 |
Correct |
60 ms |
11416 KB |
Output is correct |
61 |
Correct |
44 ms |
10988 KB |
Output is correct |
62 |
Correct |
47 ms |
11468 KB |
Output is correct |
63 |
Correct |
41 ms |
10580 KB |
Output is correct |
64 |
Correct |
42 ms |
10632 KB |
Output is correct |
65 |
Correct |
43 ms |
10960 KB |
Output is correct |
66 |
Correct |
45 ms |
10892 KB |
Output is correct |
67 |
Correct |
47 ms |
10860 KB |
Output is correct |
68 |
Correct |
48 ms |
10824 KB |
Output is correct |
69 |
Correct |
48 ms |
11700 KB |
Output is correct |
70 |
Correct |
61 ms |
11588 KB |
Output is correct |
71 |
Correct |
2 ms |
3796 KB |
Output is correct |
72 |
Correct |
3 ms |
4000 KB |
Output is correct |
73 |
Correct |
3 ms |
4052 KB |
Output is correct |
74 |
Correct |
3 ms |
3988 KB |
Output is correct |
75 |
Correct |
3 ms |
4052 KB |
Output is correct |
76 |
Correct |
3 ms |
4052 KB |
Output is correct |
77 |
Correct |
3 ms |
4052 KB |
Output is correct |
78 |
Correct |
3 ms |
4052 KB |
Output is correct |
79 |
Correct |
3 ms |
4052 KB |
Output is correct |
80 |
Correct |
46 ms |
11332 KB |
Output is correct |
81 |
Correct |
46 ms |
10880 KB |
Output is correct |
82 |
Correct |
45 ms |
10900 KB |
Output is correct |
83 |
Correct |
45 ms |
10944 KB |
Output is correct |
84 |
Correct |
2 ms |
3924 KB |
Output is correct |
85 |
Correct |
3 ms |
3924 KB |
Output is correct |
86 |
Correct |
2 ms |
3924 KB |
Output is correct |
87 |
Correct |
3 ms |
3992 KB |
Output is correct |
88 |
Correct |
3 ms |
3924 KB |
Output is correct |
89 |
Correct |
2 ms |
3924 KB |
Output is correct |
90 |
Correct |
3 ms |
3924 KB |
Output is correct |
91 |
Correct |
3 ms |
3992 KB |
Output is correct |
92 |
Correct |
3 ms |
3996 KB |
Output is correct |
93 |
Correct |
3 ms |
3992 KB |
Output is correct |
94 |
Correct |
2 ms |
3848 KB |
Output is correct |
95 |
Correct |
2 ms |
3852 KB |
Output is correct |
96 |
Correct |
2 ms |
3796 KB |
Output is correct |
97 |
Correct |
2 ms |
3796 KB |
Output is correct |
98 |
Correct |
2 ms |
3796 KB |
Output is correct |
99 |
Correct |
2 ms |
3796 KB |
Output is correct |
100 |
Correct |
2 ms |
3796 KB |
Output is correct |
101 |
Correct |
2 ms |
3796 KB |
Output is correct |
102 |
Correct |
2 ms |
3848 KB |
Output is correct |
103 |
Correct |
2 ms |
3796 KB |
Output is correct |
104 |
Correct |
6 ms |
4752 KB |
Output is correct |
105 |
Correct |
11 ms |
6236 KB |
Output is correct |
106 |
Correct |
2 ms |
3848 KB |
Output is correct |
107 |
Correct |
20 ms |
7676 KB |
Output is correct |
108 |
Correct |
25 ms |
9068 KB |
Output is correct |
109 |
Correct |
2 ms |
3796 KB |
Output is correct |
110 |
Correct |
35 ms |
10848 KB |
Output is correct |
111 |
Correct |
40 ms |
12684 KB |
Output is correct |
112 |
Correct |
2 ms |
3924 KB |
Output is correct |
113 |
Correct |
57 ms |
15524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
24 ms |
11228 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3796 KB |
Output is correct |
2 |
Correct |
2 ms |
3796 KB |
Output is correct |
3 |
Correct |
2 ms |
3796 KB |
Output is correct |
4 |
Correct |
2 ms |
3796 KB |
Output is correct |
5 |
Correct |
2 ms |
3796 KB |
Output is correct |
6 |
Correct |
2 ms |
3796 KB |
Output is correct |
7 |
Correct |
2 ms |
3848 KB |
Output is correct |
8 |
Correct |
2 ms |
3796 KB |
Output is correct |
9 |
Correct |
2 ms |
3796 KB |
Output is correct |
10 |
Correct |
2 ms |
3796 KB |
Output is correct |
11 |
Correct |
2 ms |
3848 KB |
Output is correct |
12 |
Correct |
2 ms |
3796 KB |
Output is correct |
13 |
Correct |
2 ms |
3796 KB |
Output is correct |
14 |
Correct |
2 ms |
3796 KB |
Output is correct |
15 |
Correct |
2 ms |
3796 KB |
Output is correct |
16 |
Correct |
2 ms |
3852 KB |
Output is correct |
17 |
Correct |
2 ms |
3796 KB |
Output is correct |
18 |
Correct |
2 ms |
3796 KB |
Output is correct |
19 |
Correct |
3 ms |
3796 KB |
Output is correct |
20 |
Correct |
2 ms |
3852 KB |
Output is correct |
21 |
Correct |
2 ms |
3796 KB |
Output is correct |
22 |
Correct |
2 ms |
3844 KB |
Output is correct |
23 |
Correct |
2 ms |
3796 KB |
Output is correct |
24 |
Correct |
2 ms |
3796 KB |
Output is correct |
25 |
Correct |
2 ms |
3796 KB |
Output is correct |
26 |
Incorrect |
2 ms |
3924 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
13076 KB |
Output is correct |
2 |
Correct |
36 ms |
13128 KB |
Output is correct |
3 |
Correct |
25 ms |
9844 KB |
Output is correct |
4 |
Correct |
8 ms |
5204 KB |
Output is correct |
5 |
Correct |
6 ms |
4636 KB |
Output is correct |
6 |
Correct |
11 ms |
5804 KB |
Output is correct |
7 |
Correct |
2 ms |
3796 KB |
Output is correct |
8 |
Correct |
20 ms |
7092 KB |
Output is correct |
9 |
Correct |
33 ms |
8552 KB |
Output is correct |
10 |
Correct |
2 ms |
3796 KB |
Output is correct |
11 |
Correct |
34 ms |
9712 KB |
Output is correct |
12 |
Correct |
41 ms |
11468 KB |
Output is correct |
13 |
Correct |
2 ms |
3924 KB |
Output is correct |
14 |
Correct |
2 ms |
3796 KB |
Output is correct |
15 |
Correct |
2 ms |
3796 KB |
Output is correct |
16 |
Correct |
2 ms |
3796 KB |
Output is correct |
17 |
Correct |
2 ms |
3796 KB |
Output is correct |
18 |
Correct |
2 ms |
3796 KB |
Output is correct |
19 |
Correct |
2 ms |
3796 KB |
Output is correct |
20 |
Correct |
2 ms |
3848 KB |
Output is correct |
21 |
Correct |
2 ms |
3796 KB |
Output is correct |
22 |
Correct |
2 ms |
3796 KB |
Output is correct |
23 |
Correct |
2 ms |
3796 KB |
Output is correct |
24 |
Correct |
2 ms |
3848 KB |
Output is correct |
25 |
Correct |
2 ms |
3796 KB |
Output is correct |
26 |
Correct |
2 ms |
3796 KB |
Output is correct |
27 |
Correct |
2 ms |
3796 KB |
Output is correct |
28 |
Correct |
2 ms |
3796 KB |
Output is correct |
29 |
Correct |
2 ms |
3852 KB |
Output is correct |
30 |
Correct |
2 ms |
3796 KB |
Output is correct |
31 |
Correct |
2 ms |
3796 KB |
Output is correct |
32 |
Correct |
3 ms |
3796 KB |
Output is correct |
33 |
Correct |
2 ms |
3852 KB |
Output is correct |
34 |
Correct |
2 ms |
3796 KB |
Output is correct |
35 |
Correct |
2 ms |
3844 KB |
Output is correct |
36 |
Correct |
2 ms |
3796 KB |
Output is correct |
37 |
Correct |
2 ms |
3796 KB |
Output is correct |
38 |
Correct |
2 ms |
3796 KB |
Output is correct |
39 |
Correct |
51 ms |
14412 KB |
Output is correct |
40 |
Correct |
42 ms |
14280 KB |
Output is correct |
41 |
Correct |
25 ms |
10752 KB |
Output is correct |
42 |
Correct |
7 ms |
5332 KB |
Output is correct |
43 |
Correct |
2 ms |
3796 KB |
Output is correct |
44 |
Correct |
2 ms |
3796 KB |
Output is correct |
45 |
Correct |
2 ms |
3796 KB |
Output is correct |
46 |
Correct |
2 ms |
3796 KB |
Output is correct |
47 |
Correct |
2 ms |
3796 KB |
Output is correct |
48 |
Correct |
2 ms |
3796 KB |
Output is correct |
49 |
Correct |
2 ms |
3796 KB |
Output is correct |
50 |
Correct |
2 ms |
3796 KB |
Output is correct |
51 |
Correct |
2 ms |
3796 KB |
Output is correct |
52 |
Correct |
3 ms |
3796 KB |
Output is correct |
53 |
Correct |
2 ms |
3848 KB |
Output is correct |
54 |
Correct |
2 ms |
3796 KB |
Output is correct |
55 |
Correct |
2 ms |
3796 KB |
Output is correct |
56 |
Correct |
2 ms |
3796 KB |
Output is correct |
57 |
Correct |
45 ms |
10888 KB |
Output is correct |
58 |
Correct |
61 ms |
11500 KB |
Output is correct |
59 |
Correct |
47 ms |
10848 KB |
Output is correct |
60 |
Correct |
60 ms |
11416 KB |
Output is correct |
61 |
Correct |
44 ms |
10988 KB |
Output is correct |
62 |
Correct |
47 ms |
11468 KB |
Output is correct |
63 |
Correct |
41 ms |
10580 KB |
Output is correct |
64 |
Correct |
42 ms |
10632 KB |
Output is correct |
65 |
Correct |
43 ms |
10960 KB |
Output is correct |
66 |
Correct |
45 ms |
10892 KB |
Output is correct |
67 |
Correct |
47 ms |
10860 KB |
Output is correct |
68 |
Correct |
48 ms |
10824 KB |
Output is correct |
69 |
Correct |
48 ms |
11700 KB |
Output is correct |
70 |
Correct |
61 ms |
11588 KB |
Output is correct |
71 |
Correct |
2 ms |
3796 KB |
Output is correct |
72 |
Correct |
3 ms |
4000 KB |
Output is correct |
73 |
Correct |
3 ms |
4052 KB |
Output is correct |
74 |
Correct |
3 ms |
3988 KB |
Output is correct |
75 |
Correct |
3 ms |
4052 KB |
Output is correct |
76 |
Correct |
3 ms |
4052 KB |
Output is correct |
77 |
Correct |
3 ms |
4052 KB |
Output is correct |
78 |
Correct |
3 ms |
4052 KB |
Output is correct |
79 |
Correct |
3 ms |
4052 KB |
Output is correct |
80 |
Correct |
46 ms |
11332 KB |
Output is correct |
81 |
Correct |
46 ms |
10880 KB |
Output is correct |
82 |
Correct |
45 ms |
10900 KB |
Output is correct |
83 |
Correct |
45 ms |
10944 KB |
Output is correct |
84 |
Correct |
2 ms |
3924 KB |
Output is correct |
85 |
Correct |
3 ms |
3924 KB |
Output is correct |
86 |
Correct |
2 ms |
3924 KB |
Output is correct |
87 |
Correct |
3 ms |
3992 KB |
Output is correct |
88 |
Correct |
3 ms |
3924 KB |
Output is correct |
89 |
Correct |
2 ms |
3924 KB |
Output is correct |
90 |
Correct |
3 ms |
3924 KB |
Output is correct |
91 |
Correct |
3 ms |
3992 KB |
Output is correct |
92 |
Correct |
3 ms |
3996 KB |
Output is correct |
93 |
Correct |
3 ms |
3992 KB |
Output is correct |
94 |
Correct |
2 ms |
3848 KB |
Output is correct |
95 |
Correct |
2 ms |
3852 KB |
Output is correct |
96 |
Correct |
2 ms |
3796 KB |
Output is correct |
97 |
Correct |
2 ms |
3796 KB |
Output is correct |
98 |
Correct |
2 ms |
3796 KB |
Output is correct |
99 |
Correct |
2 ms |
3796 KB |
Output is correct |
100 |
Correct |
2 ms |
3796 KB |
Output is correct |
101 |
Correct |
2 ms |
3796 KB |
Output is correct |
102 |
Correct |
2 ms |
3848 KB |
Output is correct |
103 |
Correct |
2 ms |
3796 KB |
Output is correct |
104 |
Correct |
6 ms |
4752 KB |
Output is correct |
105 |
Correct |
11 ms |
6236 KB |
Output is correct |
106 |
Correct |
2 ms |
3848 KB |
Output is correct |
107 |
Correct |
20 ms |
7676 KB |
Output is correct |
108 |
Correct |
25 ms |
9068 KB |
Output is correct |
109 |
Correct |
2 ms |
3796 KB |
Output is correct |
110 |
Correct |
35 ms |
10848 KB |
Output is correct |
111 |
Correct |
40 ms |
12684 KB |
Output is correct |
112 |
Correct |
2 ms |
3924 KB |
Output is correct |
113 |
Correct |
57 ms |
15524 KB |
Output is correct |
114 |
Incorrect |
24 ms |
11228 KB |
Output isn't correct |
115 |
Halted |
0 ms |
0 KB |
- |