#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i<= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define f first
#define s second
#define pb push_back
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef long long ll;
typedef vector<ll> vl;
const int MAXN = 100100;
const ll INF = 1e15;
int n, m;
ll l;
vii adj[MAXN];
ll dp[MAXN][2];
bool vis[MAXN];
ll mx, sm;
void dfs1 (int v, int p = -1) {
vis[v] = true;
for (auto pp : adj[v]) {
int u = pp.f;
ll w = pp.s;
if (u == p) continue;
dfs1(u, v);
ll cr = dp[u][0] + w;
if (cr > dp[v][1]) dp[v][1] = cr;
if (dp[v][1] > dp[v][0]) swap(dp[v][0], dp[v][1]);
}
mx = max(mx, dp[v][0]+dp[v][1]);
//cout << " v = " << v << " dp0 = " << dp[v][0] << " dp1 = " << dp[v][1] << endl;
}
void dfs2 (int v, int p = -1, ll prevW = 0) {
if (p != -1) {
ll cr = 0;
if (dp[p][0] != dp[v][0] + prevW)
cr = dp[p][0] + prevW;
else
cr = dp[p][1] + prevW;
if (cr > dp[v][1]) dp[v][1] = cr;
if (dp[v][1] > dp[v][0]) swap(dp[v][0], dp[v][1]);
}
for (auto pp : adj[v]) {
int u = pp.f;
ll w = pp.s;
if (u == p) continue;
dfs2(u, v, w);
}
sm = min(sm, dp[v][0]);
//cout << " dfs2 v = " << v << " dp0 = " << dp[v][0] << " dp1 = " << dp[v][1] << endl;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
n = N;
m = M;
l = L;
FOR(i, 0, m-1) {
adj[A[i]].pb({B[i], T[i]});
adj[B[i]].pb({A[i], T[i]});
}
ll ans = 0;
ll cur = l;
FOR(i, 0, n-1) {
if (vis[i]) continue;
mx = 0;
dfs1 (i);
ans = max(mx, ans);
sm = INF;
dfs2 (i);
cur += sm;
}
ans = max(ans, cur);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
12564 KB |
Output is correct |
2 |
Correct |
58 ms |
12924 KB |
Output is correct |
3 |
Correct |
38 ms |
11096 KB |
Output is correct |
4 |
Correct |
11 ms |
4300 KB |
Output is correct |
5 |
Correct |
8 ms |
3660 KB |
Output is correct |
6 |
Correct |
13 ms |
4968 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
24 ms |
7040 KB |
Output is correct |
9 |
Correct |
37 ms |
9376 KB |
Output is correct |
10 |
Correct |
2 ms |
2764 KB |
Output is correct |
11 |
Correct |
55 ms |
10464 KB |
Output is correct |
12 |
Correct |
68 ms |
11896 KB |
Output is correct |
13 |
Correct |
3 ms |
2764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2652 KB |
Output is correct |
4 |
Correct |
2 ms |
2684 KB |
Output is correct |
5 |
Correct |
2 ms |
2656 KB |
Output is correct |
6 |
Correct |
2 ms |
2636 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
9 |
Correct |
2 ms |
2636 KB |
Output is correct |
10 |
Correct |
2 ms |
2636 KB |
Output is correct |
11 |
Correct |
2 ms |
2636 KB |
Output is correct |
12 |
Correct |
3 ms |
2636 KB |
Output is correct |
13 |
Correct |
2 ms |
2648 KB |
Output is correct |
14 |
Correct |
2 ms |
2652 KB |
Output is correct |
15 |
Correct |
2 ms |
2636 KB |
Output is correct |
16 |
Correct |
2 ms |
2636 KB |
Output is correct |
17 |
Correct |
2 ms |
2656 KB |
Output is correct |
18 |
Correct |
2 ms |
2636 KB |
Output is correct |
19 |
Correct |
2 ms |
2636 KB |
Output is correct |
20 |
Correct |
2 ms |
2636 KB |
Output is correct |
21 |
Correct |
2 ms |
2636 KB |
Output is correct |
22 |
Correct |
2 ms |
2648 KB |
Output is correct |
23 |
Correct |
2 ms |
2636 KB |
Output is correct |
24 |
Correct |
2 ms |
2636 KB |
Output is correct |
25 |
Correct |
2 ms |
2636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
12564 KB |
Output is correct |
2 |
Correct |
58 ms |
12924 KB |
Output is correct |
3 |
Correct |
38 ms |
11096 KB |
Output is correct |
4 |
Correct |
11 ms |
4300 KB |
Output is correct |
5 |
Correct |
8 ms |
3660 KB |
Output is correct |
6 |
Correct |
13 ms |
4968 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
24 ms |
7040 KB |
Output is correct |
9 |
Correct |
37 ms |
9376 KB |
Output is correct |
10 |
Correct |
2 ms |
2764 KB |
Output is correct |
11 |
Correct |
55 ms |
10464 KB |
Output is correct |
12 |
Correct |
68 ms |
11896 KB |
Output is correct |
13 |
Correct |
3 ms |
2764 KB |
Output is correct |
14 |
Correct |
2 ms |
2636 KB |
Output is correct |
15 |
Correct |
2 ms |
2636 KB |
Output is correct |
16 |
Correct |
2 ms |
2652 KB |
Output is correct |
17 |
Correct |
2 ms |
2684 KB |
Output is correct |
18 |
Correct |
2 ms |
2656 KB |
Output is correct |
19 |
Correct |
2 ms |
2636 KB |
Output is correct |
20 |
Correct |
2 ms |
2636 KB |
Output is correct |
21 |
Correct |
2 ms |
2636 KB |
Output is correct |
22 |
Correct |
2 ms |
2636 KB |
Output is correct |
23 |
Correct |
2 ms |
2636 KB |
Output is correct |
24 |
Correct |
2 ms |
2636 KB |
Output is correct |
25 |
Correct |
3 ms |
2636 KB |
Output is correct |
26 |
Correct |
2 ms |
2648 KB |
Output is correct |
27 |
Correct |
2 ms |
2652 KB |
Output is correct |
28 |
Correct |
2 ms |
2636 KB |
Output is correct |
29 |
Correct |
2 ms |
2636 KB |
Output is correct |
30 |
Correct |
2 ms |
2656 KB |
Output is correct |
31 |
Correct |
2 ms |
2636 KB |
Output is correct |
32 |
Correct |
2 ms |
2636 KB |
Output is correct |
33 |
Correct |
2 ms |
2636 KB |
Output is correct |
34 |
Correct |
2 ms |
2636 KB |
Output is correct |
35 |
Correct |
2 ms |
2648 KB |
Output is correct |
36 |
Correct |
2 ms |
2636 KB |
Output is correct |
37 |
Correct |
2 ms |
2636 KB |
Output is correct |
38 |
Correct |
2 ms |
2636 KB |
Output is correct |
39 |
Correct |
71 ms |
13220 KB |
Output is correct |
40 |
Correct |
72 ms |
12868 KB |
Output is correct |
41 |
Correct |
36 ms |
11120 KB |
Output is correct |
42 |
Correct |
11 ms |
4172 KB |
Output is correct |
43 |
Correct |
2 ms |
2636 KB |
Output is correct |
44 |
Correct |
2 ms |
2636 KB |
Output is correct |
45 |
Correct |
2 ms |
2636 KB |
Output is correct |
46 |
Correct |
2 ms |
2636 KB |
Output is correct |
47 |
Correct |
2 ms |
2636 KB |
Output is correct |
48 |
Correct |
2 ms |
2636 KB |
Output is correct |
49 |
Correct |
3 ms |
2632 KB |
Output is correct |
50 |
Correct |
2 ms |
2636 KB |
Output is correct |
51 |
Correct |
2 ms |
2636 KB |
Output is correct |
52 |
Correct |
2 ms |
2660 KB |
Output is correct |
53 |
Correct |
2 ms |
2764 KB |
Output is correct |
54 |
Correct |
2 ms |
2636 KB |
Output is correct |
55 |
Correct |
2 ms |
2636 KB |
Output is correct |
56 |
Correct |
3 ms |
2764 KB |
Output is correct |
57 |
Correct |
77 ms |
10764 KB |
Output is correct |
58 |
Correct |
72 ms |
10812 KB |
Output is correct |
59 |
Correct |
82 ms |
10696 KB |
Output is correct |
60 |
Correct |
75 ms |
10664 KB |
Output is correct |
61 |
Correct |
85 ms |
10844 KB |
Output is correct |
62 |
Correct |
72 ms |
10820 KB |
Output is correct |
63 |
Correct |
85 ms |
10496 KB |
Output is correct |
64 |
Correct |
69 ms |
10504 KB |
Output is correct |
65 |
Correct |
66 ms |
10692 KB |
Output is correct |
66 |
Correct |
73 ms |
10812 KB |
Output is correct |
67 |
Correct |
74 ms |
10720 KB |
Output is correct |
68 |
Correct |
109 ms |
10756 KB |
Output is correct |
69 |
Correct |
79 ms |
11000 KB |
Output is correct |
70 |
Correct |
74 ms |
10968 KB |
Output is correct |
71 |
Correct |
2 ms |
2636 KB |
Output is correct |
72 |
Correct |
3 ms |
2892 KB |
Output is correct |
73 |
Correct |
4 ms |
2932 KB |
Output is correct |
74 |
Correct |
4 ms |
2892 KB |
Output is correct |
75 |
Correct |
4 ms |
2892 KB |
Output is correct |
76 |
Correct |
4 ms |
2928 KB |
Output is correct |
77 |
Correct |
4 ms |
2892 KB |
Output is correct |
78 |
Correct |
4 ms |
2844 KB |
Output is correct |
79 |
Correct |
3 ms |
2892 KB |
Output is correct |
80 |
Correct |
92 ms |
10640 KB |
Output is correct |
81 |
Correct |
91 ms |
10764 KB |
Output is correct |
82 |
Correct |
111 ms |
10728 KB |
Output is correct |
83 |
Correct |
93 ms |
10820 KB |
Output is correct |
84 |
Correct |
3 ms |
2764 KB |
Output is correct |
85 |
Correct |
3 ms |
2764 KB |
Output is correct |
86 |
Correct |
3 ms |
2764 KB |
Output is correct |
87 |
Correct |
3 ms |
2764 KB |
Output is correct |
88 |
Correct |
3 ms |
2836 KB |
Output is correct |
89 |
Correct |
3 ms |
2828 KB |
Output is correct |
90 |
Correct |
4 ms |
2764 KB |
Output is correct |
91 |
Correct |
4 ms |
2796 KB |
Output is correct |
92 |
Correct |
4 ms |
2892 KB |
Output is correct |
93 |
Correct |
3 ms |
2796 KB |
Output is correct |
94 |
Correct |
2 ms |
2648 KB |
Output is correct |
95 |
Correct |
2 ms |
2636 KB |
Output is correct |
96 |
Correct |
2 ms |
2636 KB |
Output is correct |
97 |
Correct |
2 ms |
2636 KB |
Output is correct |
98 |
Correct |
2 ms |
2636 KB |
Output is correct |
99 |
Correct |
2 ms |
2636 KB |
Output is correct |
100 |
Correct |
2 ms |
2636 KB |
Output is correct |
101 |
Correct |
2 ms |
2636 KB |
Output is correct |
102 |
Correct |
2 ms |
2636 KB |
Output is correct |
103 |
Correct |
2 ms |
2660 KB |
Output is correct |
104 |
Correct |
9 ms |
3532 KB |
Output is correct |
105 |
Correct |
14 ms |
4940 KB |
Output is correct |
106 |
Correct |
2 ms |
2636 KB |
Output is correct |
107 |
Correct |
29 ms |
6964 KB |
Output is correct |
108 |
Correct |
33 ms |
9292 KB |
Output is correct |
109 |
Correct |
2 ms |
2664 KB |
Output is correct |
110 |
Correct |
56 ms |
10564 KB |
Output is correct |
111 |
Correct |
86 ms |
11788 KB |
Output is correct |
112 |
Correct |
3 ms |
2764 KB |
Output is correct |
113 |
Correct |
84 ms |
17884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
22 ms |
6884 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2652 KB |
Output is correct |
4 |
Correct |
2 ms |
2684 KB |
Output is correct |
5 |
Correct |
2 ms |
2656 KB |
Output is correct |
6 |
Correct |
2 ms |
2636 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
9 |
Correct |
2 ms |
2636 KB |
Output is correct |
10 |
Correct |
2 ms |
2636 KB |
Output is correct |
11 |
Correct |
2 ms |
2636 KB |
Output is correct |
12 |
Correct |
3 ms |
2636 KB |
Output is correct |
13 |
Correct |
2 ms |
2648 KB |
Output is correct |
14 |
Correct |
2 ms |
2652 KB |
Output is correct |
15 |
Correct |
2 ms |
2636 KB |
Output is correct |
16 |
Correct |
2 ms |
2636 KB |
Output is correct |
17 |
Correct |
2 ms |
2656 KB |
Output is correct |
18 |
Correct |
2 ms |
2636 KB |
Output is correct |
19 |
Correct |
2 ms |
2636 KB |
Output is correct |
20 |
Correct |
2 ms |
2636 KB |
Output is correct |
21 |
Correct |
2 ms |
2636 KB |
Output is correct |
22 |
Correct |
2 ms |
2648 KB |
Output is correct |
23 |
Correct |
2 ms |
2636 KB |
Output is correct |
24 |
Correct |
2 ms |
2636 KB |
Output is correct |
25 |
Correct |
2 ms |
2636 KB |
Output is correct |
26 |
Correct |
3 ms |
2636 KB |
Output is correct |
27 |
Correct |
4 ms |
2784 KB |
Output is correct |
28 |
Correct |
3 ms |
2892 KB |
Output is correct |
29 |
Incorrect |
3 ms |
2664 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
12564 KB |
Output is correct |
2 |
Correct |
58 ms |
12924 KB |
Output is correct |
3 |
Correct |
38 ms |
11096 KB |
Output is correct |
4 |
Correct |
11 ms |
4300 KB |
Output is correct |
5 |
Correct |
8 ms |
3660 KB |
Output is correct |
6 |
Correct |
13 ms |
4968 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
24 ms |
7040 KB |
Output is correct |
9 |
Correct |
37 ms |
9376 KB |
Output is correct |
10 |
Correct |
2 ms |
2764 KB |
Output is correct |
11 |
Correct |
55 ms |
10464 KB |
Output is correct |
12 |
Correct |
68 ms |
11896 KB |
Output is correct |
13 |
Correct |
3 ms |
2764 KB |
Output is correct |
14 |
Correct |
2 ms |
2636 KB |
Output is correct |
15 |
Correct |
2 ms |
2636 KB |
Output is correct |
16 |
Correct |
2 ms |
2652 KB |
Output is correct |
17 |
Correct |
2 ms |
2684 KB |
Output is correct |
18 |
Correct |
2 ms |
2656 KB |
Output is correct |
19 |
Correct |
2 ms |
2636 KB |
Output is correct |
20 |
Correct |
2 ms |
2636 KB |
Output is correct |
21 |
Correct |
2 ms |
2636 KB |
Output is correct |
22 |
Correct |
2 ms |
2636 KB |
Output is correct |
23 |
Correct |
2 ms |
2636 KB |
Output is correct |
24 |
Correct |
2 ms |
2636 KB |
Output is correct |
25 |
Correct |
3 ms |
2636 KB |
Output is correct |
26 |
Correct |
2 ms |
2648 KB |
Output is correct |
27 |
Correct |
2 ms |
2652 KB |
Output is correct |
28 |
Correct |
2 ms |
2636 KB |
Output is correct |
29 |
Correct |
2 ms |
2636 KB |
Output is correct |
30 |
Correct |
2 ms |
2656 KB |
Output is correct |
31 |
Correct |
2 ms |
2636 KB |
Output is correct |
32 |
Correct |
2 ms |
2636 KB |
Output is correct |
33 |
Correct |
2 ms |
2636 KB |
Output is correct |
34 |
Correct |
2 ms |
2636 KB |
Output is correct |
35 |
Correct |
2 ms |
2648 KB |
Output is correct |
36 |
Correct |
2 ms |
2636 KB |
Output is correct |
37 |
Correct |
2 ms |
2636 KB |
Output is correct |
38 |
Correct |
2 ms |
2636 KB |
Output is correct |
39 |
Correct |
71 ms |
13220 KB |
Output is correct |
40 |
Correct |
72 ms |
12868 KB |
Output is correct |
41 |
Correct |
36 ms |
11120 KB |
Output is correct |
42 |
Correct |
11 ms |
4172 KB |
Output is correct |
43 |
Correct |
2 ms |
2636 KB |
Output is correct |
44 |
Correct |
2 ms |
2636 KB |
Output is correct |
45 |
Correct |
2 ms |
2636 KB |
Output is correct |
46 |
Correct |
2 ms |
2636 KB |
Output is correct |
47 |
Correct |
2 ms |
2636 KB |
Output is correct |
48 |
Correct |
2 ms |
2636 KB |
Output is correct |
49 |
Correct |
3 ms |
2632 KB |
Output is correct |
50 |
Correct |
2 ms |
2636 KB |
Output is correct |
51 |
Correct |
2 ms |
2636 KB |
Output is correct |
52 |
Correct |
2 ms |
2660 KB |
Output is correct |
53 |
Correct |
2 ms |
2764 KB |
Output is correct |
54 |
Correct |
2 ms |
2636 KB |
Output is correct |
55 |
Correct |
2 ms |
2636 KB |
Output is correct |
56 |
Correct |
3 ms |
2764 KB |
Output is correct |
57 |
Correct |
77 ms |
10764 KB |
Output is correct |
58 |
Correct |
72 ms |
10812 KB |
Output is correct |
59 |
Correct |
82 ms |
10696 KB |
Output is correct |
60 |
Correct |
75 ms |
10664 KB |
Output is correct |
61 |
Correct |
85 ms |
10844 KB |
Output is correct |
62 |
Correct |
72 ms |
10820 KB |
Output is correct |
63 |
Correct |
85 ms |
10496 KB |
Output is correct |
64 |
Correct |
69 ms |
10504 KB |
Output is correct |
65 |
Correct |
66 ms |
10692 KB |
Output is correct |
66 |
Correct |
73 ms |
10812 KB |
Output is correct |
67 |
Correct |
74 ms |
10720 KB |
Output is correct |
68 |
Correct |
109 ms |
10756 KB |
Output is correct |
69 |
Correct |
79 ms |
11000 KB |
Output is correct |
70 |
Correct |
74 ms |
10968 KB |
Output is correct |
71 |
Correct |
2 ms |
2636 KB |
Output is correct |
72 |
Correct |
3 ms |
2892 KB |
Output is correct |
73 |
Correct |
4 ms |
2932 KB |
Output is correct |
74 |
Correct |
4 ms |
2892 KB |
Output is correct |
75 |
Correct |
4 ms |
2892 KB |
Output is correct |
76 |
Correct |
4 ms |
2928 KB |
Output is correct |
77 |
Correct |
4 ms |
2892 KB |
Output is correct |
78 |
Correct |
4 ms |
2844 KB |
Output is correct |
79 |
Correct |
3 ms |
2892 KB |
Output is correct |
80 |
Correct |
92 ms |
10640 KB |
Output is correct |
81 |
Correct |
91 ms |
10764 KB |
Output is correct |
82 |
Correct |
111 ms |
10728 KB |
Output is correct |
83 |
Correct |
93 ms |
10820 KB |
Output is correct |
84 |
Correct |
3 ms |
2764 KB |
Output is correct |
85 |
Correct |
3 ms |
2764 KB |
Output is correct |
86 |
Correct |
3 ms |
2764 KB |
Output is correct |
87 |
Correct |
3 ms |
2764 KB |
Output is correct |
88 |
Correct |
3 ms |
2836 KB |
Output is correct |
89 |
Correct |
3 ms |
2828 KB |
Output is correct |
90 |
Correct |
4 ms |
2764 KB |
Output is correct |
91 |
Correct |
4 ms |
2796 KB |
Output is correct |
92 |
Correct |
4 ms |
2892 KB |
Output is correct |
93 |
Correct |
3 ms |
2796 KB |
Output is correct |
94 |
Correct |
2 ms |
2648 KB |
Output is correct |
95 |
Correct |
2 ms |
2636 KB |
Output is correct |
96 |
Correct |
2 ms |
2636 KB |
Output is correct |
97 |
Correct |
2 ms |
2636 KB |
Output is correct |
98 |
Correct |
2 ms |
2636 KB |
Output is correct |
99 |
Correct |
2 ms |
2636 KB |
Output is correct |
100 |
Correct |
2 ms |
2636 KB |
Output is correct |
101 |
Correct |
2 ms |
2636 KB |
Output is correct |
102 |
Correct |
2 ms |
2636 KB |
Output is correct |
103 |
Correct |
2 ms |
2660 KB |
Output is correct |
104 |
Correct |
9 ms |
3532 KB |
Output is correct |
105 |
Correct |
14 ms |
4940 KB |
Output is correct |
106 |
Correct |
2 ms |
2636 KB |
Output is correct |
107 |
Correct |
29 ms |
6964 KB |
Output is correct |
108 |
Correct |
33 ms |
9292 KB |
Output is correct |
109 |
Correct |
2 ms |
2664 KB |
Output is correct |
110 |
Correct |
56 ms |
10564 KB |
Output is correct |
111 |
Correct |
86 ms |
11788 KB |
Output is correct |
112 |
Correct |
3 ms |
2764 KB |
Output is correct |
113 |
Correct |
84 ms |
17884 KB |
Output is correct |
114 |
Incorrect |
22 ms |
6884 KB |
Output isn't correct |
115 |
Halted |
0 ms |
0 KB |
- |