#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include"dreaming.h"
typedef long long ll;
using namespace std;
const int maxn = 1e5 + 79, inf = 1e9 + 79;
vector<int> vis(maxn, 0), dp(maxn, 0);
vector<vector<pair<int, int> > > g(maxn);
void dfs1(int u, int p)
{
vis[u] = 1;
for (int i = 0; i < g[u].size(); i++) if (g[u][i].first == p) { g[u].erase(g[u].begin() + i); break; }
for (pair<int, int> i : g[u])
{
dfs1(i.first, u);
dp[u] = max(dp[u], dp[i.first] + i.second);
}
}
void dfs2(int u, int dist, int &mini, int &dia)
{
mini = min(mini, max(dist, dp[u]));
vector<int> pf(g[u].size() + 1, 0), sf(g[u].size() + 1, 0);
pair<int, int> p(0, 0);
for (int i = 0; i < g[u].size(); i++)
{
int di = dp[g[u][i].first] + g[u][i].second; pf[i + 1] = max(pf[i], di);
if (di > p.first) swap(p.first, p.second), p.first = di;
else if (di > p.second) p.second = di;
}
dia = max({ dia, p.first + p.second, dp[u] + dist });
for (int i = g[u].size() - 1; i >= 0; i--)
sf[i] = max(sf[i + 1], dp[g[u][i].first] + g[u][i].second);
for (int i = 0; i < g[u].size(); i++)
dfs2(g[u][i].first, max({ dist, pf[i], sf[i + 1] }) + g[u][i].second, mini, dia);
}
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> v; int ans = 0;
for (int i = 0; i < n; i++)
if (!vis[i])
{
v.push_back(inf);
dfs1(i, -1), dfs2(i, 0, v.back(), ans);
}
return max(v[0] + l + v[1], ans);
}
Compilation message
dreaming.cpp: In function 'void dfs1(int, int)':
dreaming.cpp:17:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for (int i = 0; i < g[u].size(); i++) if (g[u][i].first == p) { g[u].erase(g[u].begin() + i); break; }
| ~~^~~~~~~~~~~~~
dreaming.cpp: In function 'void dfs2(int, int, int&, int&)':
dreaming.cpp:29:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for (int i = 0; i < g[u].size(); i++)
| ~~^~~~~~~~~~~~~
dreaming.cpp:38:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for (int i = 0; i < g[u].size(); i++)
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
16496 KB |
Output is correct |
2 |
Correct |
62 ms |
15808 KB |
Output is correct |
3 |
Correct |
44 ms |
14972 KB |
Output is correct |
4 |
Correct |
10 ms |
5328 KB |
Output is correct |
5 |
Correct |
8 ms |
4428 KB |
Output is correct |
6 |
Correct |
15 ms |
6348 KB |
Output is correct |
7 |
Correct |
2 ms |
3404 KB |
Output is correct |
8 |
Correct |
30 ms |
8644 KB |
Output is correct |
9 |
Correct |
39 ms |
12340 KB |
Output is correct |
10 |
Correct |
3 ms |
3532 KB |
Output is correct |
11 |
Correct |
60 ms |
12800 KB |
Output is correct |
12 |
Correct |
65 ms |
14404 KB |
Output is correct |
13 |
Correct |
3 ms |
3468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3404 KB |
Output is correct |
2 |
Correct |
3 ms |
3456 KB |
Output is correct |
3 |
Correct |
3 ms |
3460 KB |
Output is correct |
4 |
Correct |
2 ms |
3404 KB |
Output is correct |
5 |
Correct |
2 ms |
3404 KB |
Output is correct |
6 |
Correct |
3 ms |
3404 KB |
Output is correct |
7 |
Correct |
2 ms |
3404 KB |
Output is correct |
8 |
Correct |
3 ms |
3404 KB |
Output is correct |
9 |
Correct |
2 ms |
3404 KB |
Output is correct |
10 |
Correct |
2 ms |
3404 KB |
Output is correct |
11 |
Correct |
2 ms |
3404 KB |
Output is correct |
12 |
Correct |
3 ms |
3404 KB |
Output is correct |
13 |
Correct |
3 ms |
3404 KB |
Output is correct |
14 |
Correct |
3 ms |
3448 KB |
Output is correct |
15 |
Correct |
2 ms |
3404 KB |
Output is correct |
16 |
Correct |
2 ms |
3404 KB |
Output is correct |
17 |
Correct |
2 ms |
3420 KB |
Output is correct |
18 |
Correct |
2 ms |
3404 KB |
Output is correct |
19 |
Correct |
2 ms |
3404 KB |
Output is correct |
20 |
Correct |
3 ms |
3452 KB |
Output is correct |
21 |
Correct |
2 ms |
3444 KB |
Output is correct |
22 |
Correct |
3 ms |
3452 KB |
Output is correct |
23 |
Correct |
2 ms |
3452 KB |
Output is correct |
24 |
Correct |
3 ms |
3404 KB |
Output is correct |
25 |
Correct |
2 ms |
3404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
16496 KB |
Output is correct |
2 |
Correct |
62 ms |
15808 KB |
Output is correct |
3 |
Correct |
44 ms |
14972 KB |
Output is correct |
4 |
Correct |
10 ms |
5328 KB |
Output is correct |
5 |
Correct |
8 ms |
4428 KB |
Output is correct |
6 |
Correct |
15 ms |
6348 KB |
Output is correct |
7 |
Correct |
2 ms |
3404 KB |
Output is correct |
8 |
Correct |
30 ms |
8644 KB |
Output is correct |
9 |
Correct |
39 ms |
12340 KB |
Output is correct |
10 |
Correct |
3 ms |
3532 KB |
Output is correct |
11 |
Correct |
60 ms |
12800 KB |
Output is correct |
12 |
Correct |
65 ms |
14404 KB |
Output is correct |
13 |
Correct |
3 ms |
3468 KB |
Output is correct |
14 |
Correct |
2 ms |
3404 KB |
Output is correct |
15 |
Correct |
3 ms |
3456 KB |
Output is correct |
16 |
Correct |
3 ms |
3460 KB |
Output is correct |
17 |
Correct |
2 ms |
3404 KB |
Output is correct |
18 |
Correct |
2 ms |
3404 KB |
Output is correct |
19 |
Correct |
3 ms |
3404 KB |
Output is correct |
20 |
Correct |
2 ms |
3404 KB |
Output is correct |
21 |
Correct |
3 ms |
3404 KB |
Output is correct |
22 |
Correct |
2 ms |
3404 KB |
Output is correct |
23 |
Correct |
2 ms |
3404 KB |
Output is correct |
24 |
Correct |
2 ms |
3404 KB |
Output is correct |
25 |
Correct |
3 ms |
3404 KB |
Output is correct |
26 |
Correct |
3 ms |
3404 KB |
Output is correct |
27 |
Correct |
3 ms |
3448 KB |
Output is correct |
28 |
Correct |
2 ms |
3404 KB |
Output is correct |
29 |
Correct |
2 ms |
3404 KB |
Output is correct |
30 |
Correct |
2 ms |
3420 KB |
Output is correct |
31 |
Correct |
2 ms |
3404 KB |
Output is correct |
32 |
Correct |
2 ms |
3404 KB |
Output is correct |
33 |
Correct |
3 ms |
3452 KB |
Output is correct |
34 |
Correct |
2 ms |
3444 KB |
Output is correct |
35 |
Correct |
3 ms |
3452 KB |
Output is correct |
36 |
Correct |
2 ms |
3452 KB |
Output is correct |
37 |
Correct |
3 ms |
3404 KB |
Output is correct |
38 |
Correct |
2 ms |
3404 KB |
Output is correct |
39 |
Correct |
64 ms |
16528 KB |
Output is correct |
40 |
Correct |
61 ms |
15804 KB |
Output is correct |
41 |
Correct |
44 ms |
14976 KB |
Output is correct |
42 |
Correct |
10 ms |
5324 KB |
Output is correct |
43 |
Correct |
2 ms |
3404 KB |
Output is correct |
44 |
Correct |
2 ms |
3408 KB |
Output is correct |
45 |
Correct |
2 ms |
3404 KB |
Output is correct |
46 |
Correct |
3 ms |
3404 KB |
Output is correct |
47 |
Correct |
3 ms |
3404 KB |
Output is correct |
48 |
Correct |
2 ms |
3404 KB |
Output is correct |
49 |
Correct |
2 ms |
3404 KB |
Output is correct |
50 |
Correct |
3 ms |
3404 KB |
Output is correct |
51 |
Correct |
2 ms |
3404 KB |
Output is correct |
52 |
Correct |
3 ms |
3448 KB |
Output is correct |
53 |
Correct |
2 ms |
3404 KB |
Output is correct |
54 |
Correct |
2 ms |
3404 KB |
Output is correct |
55 |
Correct |
2 ms |
3404 KB |
Output is correct |
56 |
Correct |
2 ms |
3404 KB |
Output is correct |
57 |
Correct |
72 ms |
9912 KB |
Output is correct |
58 |
Correct |
73 ms |
9928 KB |
Output is correct |
59 |
Correct |
70 ms |
9900 KB |
Output is correct |
60 |
Correct |
74 ms |
9796 KB |
Output is correct |
61 |
Correct |
70 ms |
9924 KB |
Output is correct |
62 |
Correct |
67 ms |
9960 KB |
Output is correct |
63 |
Correct |
67 ms |
9540 KB |
Output is correct |
64 |
Correct |
65 ms |
9536 KB |
Output is correct |
65 |
Correct |
69 ms |
9812 KB |
Output is correct |
66 |
Correct |
70 ms |
9912 KB |
Output is correct |
67 |
Correct |
71 ms |
9908 KB |
Output is correct |
68 |
Correct |
67 ms |
9928 KB |
Output is correct |
69 |
Correct |
72 ms |
10180 KB |
Output is correct |
70 |
Correct |
73 ms |
10164 KB |
Output is correct |
71 |
Correct |
2 ms |
3404 KB |
Output is correct |
72 |
Correct |
4 ms |
3532 KB |
Output is correct |
73 |
Correct |
4 ms |
3660 KB |
Output is correct |
74 |
Correct |
4 ms |
3532 KB |
Output is correct |
75 |
Correct |
4 ms |
3532 KB |
Output is correct |
76 |
Correct |
4 ms |
3664 KB |
Output is correct |
77 |
Correct |
4 ms |
3532 KB |
Output is correct |
78 |
Correct |
4 ms |
3600 KB |
Output is correct |
79 |
Correct |
4 ms |
3584 KB |
Output is correct |
80 |
Correct |
71 ms |
9884 KB |
Output is correct |
81 |
Correct |
67 ms |
9796 KB |
Output is correct |
82 |
Correct |
70 ms |
9852 KB |
Output is correct |
83 |
Correct |
69 ms |
9988 KB |
Output is correct |
84 |
Correct |
4 ms |
3532 KB |
Output is correct |
85 |
Correct |
3 ms |
3536 KB |
Output is correct |
86 |
Correct |
4 ms |
3532 KB |
Output is correct |
87 |
Correct |
4 ms |
3660 KB |
Output is correct |
88 |
Correct |
4 ms |
3532 KB |
Output is correct |
89 |
Correct |
4 ms |
3596 KB |
Output is correct |
90 |
Correct |
4 ms |
3532 KB |
Output is correct |
91 |
Correct |
4 ms |
3532 KB |
Output is correct |
92 |
Correct |
4 ms |
3636 KB |
Output is correct |
93 |
Correct |
4 ms |
3532 KB |
Output is correct |
94 |
Correct |
2 ms |
3404 KB |
Output is correct |
95 |
Correct |
2 ms |
3404 KB |
Output is correct |
96 |
Correct |
2 ms |
3404 KB |
Output is correct |
97 |
Correct |
2 ms |
3404 KB |
Output is correct |
98 |
Correct |
2 ms |
3392 KB |
Output is correct |
99 |
Correct |
2 ms |
3404 KB |
Output is correct |
100 |
Correct |
3 ms |
3404 KB |
Output is correct |
101 |
Correct |
2 ms |
3404 KB |
Output is correct |
102 |
Correct |
3 ms |
3404 KB |
Output is correct |
103 |
Correct |
3 ms |
3404 KB |
Output is correct |
104 |
Correct |
10 ms |
4428 KB |
Output is correct |
105 |
Correct |
16 ms |
6252 KB |
Output is correct |
106 |
Correct |
2 ms |
3404 KB |
Output is correct |
107 |
Correct |
29 ms |
8664 KB |
Output is correct |
108 |
Correct |
41 ms |
12288 KB |
Output is correct |
109 |
Correct |
3 ms |
3532 KB |
Output is correct |
110 |
Correct |
54 ms |
12712 KB |
Output is correct |
111 |
Correct |
66 ms |
14404 KB |
Output is correct |
112 |
Correct |
3 ms |
3532 KB |
Output is correct |
113 |
Correct |
99 ms |
24768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
26 ms |
6480 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3404 KB |
Output is correct |
2 |
Correct |
3 ms |
3456 KB |
Output is correct |
3 |
Correct |
3 ms |
3460 KB |
Output is correct |
4 |
Correct |
2 ms |
3404 KB |
Output is correct |
5 |
Correct |
2 ms |
3404 KB |
Output is correct |
6 |
Correct |
3 ms |
3404 KB |
Output is correct |
7 |
Correct |
2 ms |
3404 KB |
Output is correct |
8 |
Correct |
3 ms |
3404 KB |
Output is correct |
9 |
Correct |
2 ms |
3404 KB |
Output is correct |
10 |
Correct |
2 ms |
3404 KB |
Output is correct |
11 |
Correct |
2 ms |
3404 KB |
Output is correct |
12 |
Correct |
3 ms |
3404 KB |
Output is correct |
13 |
Correct |
3 ms |
3404 KB |
Output is correct |
14 |
Correct |
3 ms |
3448 KB |
Output is correct |
15 |
Correct |
2 ms |
3404 KB |
Output is correct |
16 |
Correct |
2 ms |
3404 KB |
Output is correct |
17 |
Correct |
2 ms |
3420 KB |
Output is correct |
18 |
Correct |
2 ms |
3404 KB |
Output is correct |
19 |
Correct |
2 ms |
3404 KB |
Output is correct |
20 |
Correct |
3 ms |
3452 KB |
Output is correct |
21 |
Correct |
2 ms |
3444 KB |
Output is correct |
22 |
Correct |
3 ms |
3452 KB |
Output is correct |
23 |
Correct |
2 ms |
3452 KB |
Output is correct |
24 |
Correct |
3 ms |
3404 KB |
Output is correct |
25 |
Correct |
2 ms |
3404 KB |
Output is correct |
26 |
Correct |
3 ms |
3404 KB |
Output is correct |
27 |
Correct |
3 ms |
3472 KB |
Output is correct |
28 |
Correct |
4 ms |
3504 KB |
Output is correct |
29 |
Incorrect |
3 ms |
3404 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
16496 KB |
Output is correct |
2 |
Correct |
62 ms |
15808 KB |
Output is correct |
3 |
Correct |
44 ms |
14972 KB |
Output is correct |
4 |
Correct |
10 ms |
5328 KB |
Output is correct |
5 |
Correct |
8 ms |
4428 KB |
Output is correct |
6 |
Correct |
15 ms |
6348 KB |
Output is correct |
7 |
Correct |
2 ms |
3404 KB |
Output is correct |
8 |
Correct |
30 ms |
8644 KB |
Output is correct |
9 |
Correct |
39 ms |
12340 KB |
Output is correct |
10 |
Correct |
3 ms |
3532 KB |
Output is correct |
11 |
Correct |
60 ms |
12800 KB |
Output is correct |
12 |
Correct |
65 ms |
14404 KB |
Output is correct |
13 |
Correct |
3 ms |
3468 KB |
Output is correct |
14 |
Correct |
2 ms |
3404 KB |
Output is correct |
15 |
Correct |
3 ms |
3456 KB |
Output is correct |
16 |
Correct |
3 ms |
3460 KB |
Output is correct |
17 |
Correct |
2 ms |
3404 KB |
Output is correct |
18 |
Correct |
2 ms |
3404 KB |
Output is correct |
19 |
Correct |
3 ms |
3404 KB |
Output is correct |
20 |
Correct |
2 ms |
3404 KB |
Output is correct |
21 |
Correct |
3 ms |
3404 KB |
Output is correct |
22 |
Correct |
2 ms |
3404 KB |
Output is correct |
23 |
Correct |
2 ms |
3404 KB |
Output is correct |
24 |
Correct |
2 ms |
3404 KB |
Output is correct |
25 |
Correct |
3 ms |
3404 KB |
Output is correct |
26 |
Correct |
3 ms |
3404 KB |
Output is correct |
27 |
Correct |
3 ms |
3448 KB |
Output is correct |
28 |
Correct |
2 ms |
3404 KB |
Output is correct |
29 |
Correct |
2 ms |
3404 KB |
Output is correct |
30 |
Correct |
2 ms |
3420 KB |
Output is correct |
31 |
Correct |
2 ms |
3404 KB |
Output is correct |
32 |
Correct |
2 ms |
3404 KB |
Output is correct |
33 |
Correct |
3 ms |
3452 KB |
Output is correct |
34 |
Correct |
2 ms |
3444 KB |
Output is correct |
35 |
Correct |
3 ms |
3452 KB |
Output is correct |
36 |
Correct |
2 ms |
3452 KB |
Output is correct |
37 |
Correct |
3 ms |
3404 KB |
Output is correct |
38 |
Correct |
2 ms |
3404 KB |
Output is correct |
39 |
Correct |
64 ms |
16528 KB |
Output is correct |
40 |
Correct |
61 ms |
15804 KB |
Output is correct |
41 |
Correct |
44 ms |
14976 KB |
Output is correct |
42 |
Correct |
10 ms |
5324 KB |
Output is correct |
43 |
Correct |
2 ms |
3404 KB |
Output is correct |
44 |
Correct |
2 ms |
3408 KB |
Output is correct |
45 |
Correct |
2 ms |
3404 KB |
Output is correct |
46 |
Correct |
3 ms |
3404 KB |
Output is correct |
47 |
Correct |
3 ms |
3404 KB |
Output is correct |
48 |
Correct |
2 ms |
3404 KB |
Output is correct |
49 |
Correct |
2 ms |
3404 KB |
Output is correct |
50 |
Correct |
3 ms |
3404 KB |
Output is correct |
51 |
Correct |
2 ms |
3404 KB |
Output is correct |
52 |
Correct |
3 ms |
3448 KB |
Output is correct |
53 |
Correct |
2 ms |
3404 KB |
Output is correct |
54 |
Correct |
2 ms |
3404 KB |
Output is correct |
55 |
Correct |
2 ms |
3404 KB |
Output is correct |
56 |
Correct |
2 ms |
3404 KB |
Output is correct |
57 |
Correct |
72 ms |
9912 KB |
Output is correct |
58 |
Correct |
73 ms |
9928 KB |
Output is correct |
59 |
Correct |
70 ms |
9900 KB |
Output is correct |
60 |
Correct |
74 ms |
9796 KB |
Output is correct |
61 |
Correct |
70 ms |
9924 KB |
Output is correct |
62 |
Correct |
67 ms |
9960 KB |
Output is correct |
63 |
Correct |
67 ms |
9540 KB |
Output is correct |
64 |
Correct |
65 ms |
9536 KB |
Output is correct |
65 |
Correct |
69 ms |
9812 KB |
Output is correct |
66 |
Correct |
70 ms |
9912 KB |
Output is correct |
67 |
Correct |
71 ms |
9908 KB |
Output is correct |
68 |
Correct |
67 ms |
9928 KB |
Output is correct |
69 |
Correct |
72 ms |
10180 KB |
Output is correct |
70 |
Correct |
73 ms |
10164 KB |
Output is correct |
71 |
Correct |
2 ms |
3404 KB |
Output is correct |
72 |
Correct |
4 ms |
3532 KB |
Output is correct |
73 |
Correct |
4 ms |
3660 KB |
Output is correct |
74 |
Correct |
4 ms |
3532 KB |
Output is correct |
75 |
Correct |
4 ms |
3532 KB |
Output is correct |
76 |
Correct |
4 ms |
3664 KB |
Output is correct |
77 |
Correct |
4 ms |
3532 KB |
Output is correct |
78 |
Correct |
4 ms |
3600 KB |
Output is correct |
79 |
Correct |
4 ms |
3584 KB |
Output is correct |
80 |
Correct |
71 ms |
9884 KB |
Output is correct |
81 |
Correct |
67 ms |
9796 KB |
Output is correct |
82 |
Correct |
70 ms |
9852 KB |
Output is correct |
83 |
Correct |
69 ms |
9988 KB |
Output is correct |
84 |
Correct |
4 ms |
3532 KB |
Output is correct |
85 |
Correct |
3 ms |
3536 KB |
Output is correct |
86 |
Correct |
4 ms |
3532 KB |
Output is correct |
87 |
Correct |
4 ms |
3660 KB |
Output is correct |
88 |
Correct |
4 ms |
3532 KB |
Output is correct |
89 |
Correct |
4 ms |
3596 KB |
Output is correct |
90 |
Correct |
4 ms |
3532 KB |
Output is correct |
91 |
Correct |
4 ms |
3532 KB |
Output is correct |
92 |
Correct |
4 ms |
3636 KB |
Output is correct |
93 |
Correct |
4 ms |
3532 KB |
Output is correct |
94 |
Correct |
2 ms |
3404 KB |
Output is correct |
95 |
Correct |
2 ms |
3404 KB |
Output is correct |
96 |
Correct |
2 ms |
3404 KB |
Output is correct |
97 |
Correct |
2 ms |
3404 KB |
Output is correct |
98 |
Correct |
2 ms |
3392 KB |
Output is correct |
99 |
Correct |
2 ms |
3404 KB |
Output is correct |
100 |
Correct |
3 ms |
3404 KB |
Output is correct |
101 |
Correct |
2 ms |
3404 KB |
Output is correct |
102 |
Correct |
3 ms |
3404 KB |
Output is correct |
103 |
Correct |
3 ms |
3404 KB |
Output is correct |
104 |
Correct |
10 ms |
4428 KB |
Output is correct |
105 |
Correct |
16 ms |
6252 KB |
Output is correct |
106 |
Correct |
2 ms |
3404 KB |
Output is correct |
107 |
Correct |
29 ms |
8664 KB |
Output is correct |
108 |
Correct |
41 ms |
12288 KB |
Output is correct |
109 |
Correct |
3 ms |
3532 KB |
Output is correct |
110 |
Correct |
54 ms |
12712 KB |
Output is correct |
111 |
Correct |
66 ms |
14404 KB |
Output is correct |
112 |
Correct |
3 ms |
3532 KB |
Output is correct |
113 |
Correct |
99 ms |
24768 KB |
Output is correct |
114 |
Incorrect |
26 ms |
6480 KB |
Output isn't correct |
115 |
Halted |
0 ms |
0 KB |
- |