#include<bits/stdc++.h>
#include"dreaming.h"
using namespace std;
typedef long long ll;
const int maxn = 1e5;
vector<vector<pair<int, int>>> g(maxn+5);
vector<bool> vis(maxn+5, false);
vector<ll> dt(maxn+5), ht(maxn+5, 0), group(maxn+5);
vector<multiset<ll>> S(maxn+5);
void dfs1(int v, int P){
group[v] = P;
vis[v] = 1;
int maxi1 = 0, maxi2 = 0;
for(pair<int, int> pp : g[v]){
int u = pp.first, w = pp.second;
if(vis[u])
continue;
dfs1(u, P);
ht[v] = max(ht[v], ht[u]+w);
if(ht[u]+w >= maxi1){
maxi2 = maxi1, maxi1 = ht[u]+w;
} else if(ht[u]+w >= maxi2){
maxi2 = ht[u]+w;
}
}
dt[v] = maxi1+maxi2;
}
void dfs2(int v, int p){
vis[v] = 1;
for(pair<int, int> pp : g[v]){
int u = pp.first, w = pp.second;
if(u == p)
continue;
S[v].insert(ht[u]+w);
}
for(pair<int, int> pp : g[v]){
int u = pp.first, w = pp.second;
if(u == p)
continue;
if(S[v].size() == 1){
S[u].insert(w);
} else if(!S[v].empty()){
S[v].erase(S[v].find(ht[u]+w));
int best = *--S[v].end();
S[u].insert(best+w);
S[v].insert(ht[u]+w);
}
}
if(!S[v].empty())
ht[v] = *--S[v].end();
for(pair<int, int> pp : g[v]){
int u = pp.first;
if(vis[u])
continue;
dfs2(u, v);
}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]){
for(int i = 0; i < M; i++){
g[A[i]].emplace_back(B[i], T[i]);
g[B[i]].emplace_back(A[i], T[i]);
}
for(int i = 0; i < N; i++)
if(!vis[i])
dfs1(i, i);
fill(vis.begin(), vis.end(), false);
for(int i = 0; i < N; i++)
if(!vis[i])
dfs2(i, -1);
long long ans = 0;
for(int i = 0; i < N; i++)
ans = max(ans, dt[i]);
vector<pair<int, int>> order;
order.reserve(N);
for(int i = 0; i < N; i++)
order.emplace_back(ht[i], group[i]);
sort(order.begin(), order.end());
vector<int> G;
G.reserve(N);
vector<bool> used(N+5, false);
for(int i = 0; i < N; i++){
if(used[order[i].second])
continue;
G.emplace_back(order[i].first);
used[order[i].second] = true;
}
int GN = G.size();
sort(G.begin(), G.end(), [&](int n1, int n2){
return n1 > n2;
});
if(GN >= 2)
swap(G[0], G[1]);
for(int i = GN-1; i > 0; i--)
ans = max(ans, (long long) G[0] + (long long) G[i] + i*1ll*L);
return ans;
}
/*int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, l;
cin >> n >> m >> l;
int a[m], b[m], c[m];
for(int i = 0; i < n; i++)
cin >> a[i] >> b[i] >> c[i];
cout << travelTime(n, m, l, a, b, c) << "\n";
}*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
87 ms |
29272 KB |
Output is correct |
2 |
Correct |
84 ms |
28768 KB |
Output is correct |
3 |
Correct |
54 ms |
24800 KB |
Output is correct |
4 |
Correct |
15 ms |
12496 KB |
Output is correct |
5 |
Correct |
12 ms |
11476 KB |
Output is correct |
6 |
Correct |
22 ms |
13908 KB |
Output is correct |
7 |
Correct |
5 ms |
9684 KB |
Output is correct |
8 |
Correct |
42 ms |
17940 KB |
Output is correct |
9 |
Correct |
56 ms |
21800 KB |
Output is correct |
10 |
Correct |
5 ms |
9812 KB |
Output is correct |
11 |
Correct |
79 ms |
24016 KB |
Output is correct |
12 |
Correct |
93 ms |
26440 KB |
Output is correct |
13 |
Correct |
5 ms |
9896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9812 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
5 ms |
9644 KB |
Output is correct |
5 |
Correct |
5 ms |
9684 KB |
Output is correct |
6 |
Correct |
5 ms |
9684 KB |
Output is correct |
7 |
Correct |
5 ms |
9684 KB |
Output is correct |
8 |
Correct |
5 ms |
9684 KB |
Output is correct |
9 |
Correct |
5 ms |
9684 KB |
Output is correct |
10 |
Correct |
5 ms |
9684 KB |
Output is correct |
11 |
Correct |
5 ms |
9684 KB |
Output is correct |
12 |
Correct |
5 ms |
9684 KB |
Output is correct |
13 |
Correct |
5 ms |
9684 KB |
Output is correct |
14 |
Correct |
5 ms |
9684 KB |
Output is correct |
15 |
Correct |
5 ms |
9684 KB |
Output is correct |
16 |
Correct |
5 ms |
9684 KB |
Output is correct |
17 |
Correct |
5 ms |
9684 KB |
Output is correct |
18 |
Correct |
5 ms |
9684 KB |
Output is correct |
19 |
Correct |
5 ms |
9684 KB |
Output is correct |
20 |
Correct |
5 ms |
9684 KB |
Output is correct |
21 |
Correct |
5 ms |
9684 KB |
Output is correct |
22 |
Correct |
5 ms |
9684 KB |
Output is correct |
23 |
Correct |
5 ms |
9684 KB |
Output is correct |
24 |
Correct |
5 ms |
9684 KB |
Output is correct |
25 |
Correct |
4 ms |
9684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
87 ms |
29272 KB |
Output is correct |
2 |
Correct |
84 ms |
28768 KB |
Output is correct |
3 |
Correct |
54 ms |
24800 KB |
Output is correct |
4 |
Correct |
15 ms |
12496 KB |
Output is correct |
5 |
Correct |
12 ms |
11476 KB |
Output is correct |
6 |
Correct |
22 ms |
13908 KB |
Output is correct |
7 |
Correct |
5 ms |
9684 KB |
Output is correct |
8 |
Correct |
42 ms |
17940 KB |
Output is correct |
9 |
Correct |
56 ms |
21800 KB |
Output is correct |
10 |
Correct |
5 ms |
9812 KB |
Output is correct |
11 |
Correct |
79 ms |
24016 KB |
Output is correct |
12 |
Correct |
93 ms |
26440 KB |
Output is correct |
13 |
Correct |
5 ms |
9896 KB |
Output is correct |
14 |
Correct |
5 ms |
9812 KB |
Output is correct |
15 |
Correct |
5 ms |
9684 KB |
Output is correct |
16 |
Correct |
5 ms |
9684 KB |
Output is correct |
17 |
Correct |
5 ms |
9644 KB |
Output is correct |
18 |
Correct |
5 ms |
9684 KB |
Output is correct |
19 |
Correct |
5 ms |
9684 KB |
Output is correct |
20 |
Correct |
5 ms |
9684 KB |
Output is correct |
21 |
Correct |
5 ms |
9684 KB |
Output is correct |
22 |
Correct |
5 ms |
9684 KB |
Output is correct |
23 |
Correct |
5 ms |
9684 KB |
Output is correct |
24 |
Correct |
5 ms |
9684 KB |
Output is correct |
25 |
Correct |
5 ms |
9684 KB |
Output is correct |
26 |
Correct |
5 ms |
9684 KB |
Output is correct |
27 |
Correct |
5 ms |
9684 KB |
Output is correct |
28 |
Correct |
5 ms |
9684 KB |
Output is correct |
29 |
Correct |
5 ms |
9684 KB |
Output is correct |
30 |
Correct |
5 ms |
9684 KB |
Output is correct |
31 |
Correct |
5 ms |
9684 KB |
Output is correct |
32 |
Correct |
5 ms |
9684 KB |
Output is correct |
33 |
Correct |
5 ms |
9684 KB |
Output is correct |
34 |
Correct |
5 ms |
9684 KB |
Output is correct |
35 |
Correct |
5 ms |
9684 KB |
Output is correct |
36 |
Correct |
5 ms |
9684 KB |
Output is correct |
37 |
Correct |
5 ms |
9684 KB |
Output is correct |
38 |
Correct |
4 ms |
9684 KB |
Output is correct |
39 |
Correct |
82 ms |
29232 KB |
Output is correct |
40 |
Correct |
88 ms |
28812 KB |
Output is correct |
41 |
Correct |
56 ms |
24740 KB |
Output is correct |
42 |
Correct |
15 ms |
12500 KB |
Output is correct |
43 |
Correct |
5 ms |
9684 KB |
Output is correct |
44 |
Correct |
5 ms |
9684 KB |
Output is correct |
45 |
Correct |
5 ms |
9684 KB |
Output is correct |
46 |
Correct |
5 ms |
9684 KB |
Output is correct |
47 |
Correct |
5 ms |
9684 KB |
Output is correct |
48 |
Correct |
5 ms |
9684 KB |
Output is correct |
49 |
Correct |
5 ms |
9684 KB |
Output is correct |
50 |
Correct |
5 ms |
9684 KB |
Output is correct |
51 |
Correct |
5 ms |
9684 KB |
Output is correct |
52 |
Correct |
5 ms |
9684 KB |
Output is correct |
53 |
Correct |
5 ms |
9684 KB |
Output is correct |
54 |
Correct |
5 ms |
9684 KB |
Output is correct |
55 |
Correct |
5 ms |
9684 KB |
Output is correct |
56 |
Correct |
5 ms |
9684 KB |
Output is correct |
57 |
Correct |
109 ms |
25064 KB |
Output is correct |
58 |
Correct |
118 ms |
24972 KB |
Output is correct |
59 |
Correct |
109 ms |
24984 KB |
Output is correct |
60 |
Correct |
110 ms |
24944 KB |
Output is correct |
61 |
Correct |
109 ms |
24900 KB |
Output is correct |
62 |
Correct |
111 ms |
24908 KB |
Output is correct |
63 |
Correct |
109 ms |
24880 KB |
Output is correct |
64 |
Correct |
109 ms |
24744 KB |
Output is correct |
65 |
Correct |
107 ms |
24728 KB |
Output is correct |
66 |
Correct |
109 ms |
24700 KB |
Output is correct |
67 |
Correct |
113 ms |
25032 KB |
Output is correct |
68 |
Correct |
120 ms |
25152 KB |
Output is correct |
69 |
Correct |
114 ms |
25044 KB |
Output is correct |
70 |
Correct |
112 ms |
25016 KB |
Output is correct |
71 |
Correct |
5 ms |
9684 KB |
Output is correct |
72 |
Correct |
7 ms |
10196 KB |
Output is correct |
73 |
Correct |
7 ms |
10144 KB |
Output is correct |
74 |
Correct |
7 ms |
10140 KB |
Output is correct |
75 |
Correct |
7 ms |
10196 KB |
Output is correct |
76 |
Correct |
7 ms |
10196 KB |
Output is correct |
77 |
Correct |
7 ms |
10196 KB |
Output is correct |
78 |
Correct |
7 ms |
10128 KB |
Output is correct |
79 |
Correct |
7 ms |
10176 KB |
Output is correct |
80 |
Correct |
116 ms |
25128 KB |
Output is correct |
81 |
Correct |
112 ms |
24928 KB |
Output is correct |
82 |
Correct |
116 ms |
24824 KB |
Output is correct |
83 |
Correct |
111 ms |
24872 KB |
Output is correct |
84 |
Correct |
7 ms |
10016 KB |
Output is correct |
85 |
Correct |
6 ms |
10068 KB |
Output is correct |
86 |
Correct |
7 ms |
10068 KB |
Output is correct |
87 |
Correct |
7 ms |
10140 KB |
Output is correct |
88 |
Correct |
7 ms |
10068 KB |
Output is correct |
89 |
Correct |
7 ms |
10068 KB |
Output is correct |
90 |
Correct |
7 ms |
10064 KB |
Output is correct |
91 |
Correct |
7 ms |
10196 KB |
Output is correct |
92 |
Correct |
7 ms |
10068 KB |
Output is correct |
93 |
Correct |
7 ms |
10068 KB |
Output is correct |
94 |
Correct |
5 ms |
9684 KB |
Output is correct |
95 |
Correct |
5 ms |
9684 KB |
Output is correct |
96 |
Correct |
4 ms |
9684 KB |
Output is correct |
97 |
Correct |
5 ms |
9684 KB |
Output is correct |
98 |
Correct |
5 ms |
9684 KB |
Output is correct |
99 |
Correct |
5 ms |
9684 KB |
Output is correct |
100 |
Correct |
5 ms |
9684 KB |
Output is correct |
101 |
Correct |
5 ms |
9756 KB |
Output is correct |
102 |
Correct |
5 ms |
9684 KB |
Output is correct |
103 |
Correct |
5 ms |
9684 KB |
Output is correct |
104 |
Correct |
12 ms |
11544 KB |
Output is correct |
105 |
Correct |
22 ms |
14060 KB |
Output is correct |
106 |
Correct |
5 ms |
9684 KB |
Output is correct |
107 |
Correct |
39 ms |
17940 KB |
Output is correct |
108 |
Correct |
52 ms |
21864 KB |
Output is correct |
109 |
Correct |
5 ms |
9812 KB |
Output is correct |
110 |
Correct |
75 ms |
23920 KB |
Output is correct |
111 |
Correct |
89 ms |
26444 KB |
Output is correct |
112 |
Correct |
5 ms |
9812 KB |
Output is correct |
113 |
Correct |
146 ms |
36672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
40 ms |
15852 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9812 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
5 ms |
9644 KB |
Output is correct |
5 |
Correct |
5 ms |
9684 KB |
Output is correct |
6 |
Correct |
5 ms |
9684 KB |
Output is correct |
7 |
Correct |
5 ms |
9684 KB |
Output is correct |
8 |
Correct |
5 ms |
9684 KB |
Output is correct |
9 |
Correct |
5 ms |
9684 KB |
Output is correct |
10 |
Correct |
5 ms |
9684 KB |
Output is correct |
11 |
Correct |
5 ms |
9684 KB |
Output is correct |
12 |
Correct |
5 ms |
9684 KB |
Output is correct |
13 |
Correct |
5 ms |
9684 KB |
Output is correct |
14 |
Correct |
5 ms |
9684 KB |
Output is correct |
15 |
Correct |
5 ms |
9684 KB |
Output is correct |
16 |
Correct |
5 ms |
9684 KB |
Output is correct |
17 |
Correct |
5 ms |
9684 KB |
Output is correct |
18 |
Correct |
5 ms |
9684 KB |
Output is correct |
19 |
Correct |
5 ms |
9684 KB |
Output is correct |
20 |
Correct |
5 ms |
9684 KB |
Output is correct |
21 |
Correct |
5 ms |
9684 KB |
Output is correct |
22 |
Correct |
5 ms |
9684 KB |
Output is correct |
23 |
Correct |
5 ms |
9684 KB |
Output is correct |
24 |
Correct |
5 ms |
9684 KB |
Output is correct |
25 |
Correct |
4 ms |
9684 KB |
Output is correct |
26 |
Correct |
5 ms |
9812 KB |
Output is correct |
27 |
Incorrect |
6 ms |
10008 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
87 ms |
29272 KB |
Output is correct |
2 |
Correct |
84 ms |
28768 KB |
Output is correct |
3 |
Correct |
54 ms |
24800 KB |
Output is correct |
4 |
Correct |
15 ms |
12496 KB |
Output is correct |
5 |
Correct |
12 ms |
11476 KB |
Output is correct |
6 |
Correct |
22 ms |
13908 KB |
Output is correct |
7 |
Correct |
5 ms |
9684 KB |
Output is correct |
8 |
Correct |
42 ms |
17940 KB |
Output is correct |
9 |
Correct |
56 ms |
21800 KB |
Output is correct |
10 |
Correct |
5 ms |
9812 KB |
Output is correct |
11 |
Correct |
79 ms |
24016 KB |
Output is correct |
12 |
Correct |
93 ms |
26440 KB |
Output is correct |
13 |
Correct |
5 ms |
9896 KB |
Output is correct |
14 |
Correct |
5 ms |
9812 KB |
Output is correct |
15 |
Correct |
5 ms |
9684 KB |
Output is correct |
16 |
Correct |
5 ms |
9684 KB |
Output is correct |
17 |
Correct |
5 ms |
9644 KB |
Output is correct |
18 |
Correct |
5 ms |
9684 KB |
Output is correct |
19 |
Correct |
5 ms |
9684 KB |
Output is correct |
20 |
Correct |
5 ms |
9684 KB |
Output is correct |
21 |
Correct |
5 ms |
9684 KB |
Output is correct |
22 |
Correct |
5 ms |
9684 KB |
Output is correct |
23 |
Correct |
5 ms |
9684 KB |
Output is correct |
24 |
Correct |
5 ms |
9684 KB |
Output is correct |
25 |
Correct |
5 ms |
9684 KB |
Output is correct |
26 |
Correct |
5 ms |
9684 KB |
Output is correct |
27 |
Correct |
5 ms |
9684 KB |
Output is correct |
28 |
Correct |
5 ms |
9684 KB |
Output is correct |
29 |
Correct |
5 ms |
9684 KB |
Output is correct |
30 |
Correct |
5 ms |
9684 KB |
Output is correct |
31 |
Correct |
5 ms |
9684 KB |
Output is correct |
32 |
Correct |
5 ms |
9684 KB |
Output is correct |
33 |
Correct |
5 ms |
9684 KB |
Output is correct |
34 |
Correct |
5 ms |
9684 KB |
Output is correct |
35 |
Correct |
5 ms |
9684 KB |
Output is correct |
36 |
Correct |
5 ms |
9684 KB |
Output is correct |
37 |
Correct |
5 ms |
9684 KB |
Output is correct |
38 |
Correct |
4 ms |
9684 KB |
Output is correct |
39 |
Correct |
82 ms |
29232 KB |
Output is correct |
40 |
Correct |
88 ms |
28812 KB |
Output is correct |
41 |
Correct |
56 ms |
24740 KB |
Output is correct |
42 |
Correct |
15 ms |
12500 KB |
Output is correct |
43 |
Correct |
5 ms |
9684 KB |
Output is correct |
44 |
Correct |
5 ms |
9684 KB |
Output is correct |
45 |
Correct |
5 ms |
9684 KB |
Output is correct |
46 |
Correct |
5 ms |
9684 KB |
Output is correct |
47 |
Correct |
5 ms |
9684 KB |
Output is correct |
48 |
Correct |
5 ms |
9684 KB |
Output is correct |
49 |
Correct |
5 ms |
9684 KB |
Output is correct |
50 |
Correct |
5 ms |
9684 KB |
Output is correct |
51 |
Correct |
5 ms |
9684 KB |
Output is correct |
52 |
Correct |
5 ms |
9684 KB |
Output is correct |
53 |
Correct |
5 ms |
9684 KB |
Output is correct |
54 |
Correct |
5 ms |
9684 KB |
Output is correct |
55 |
Correct |
5 ms |
9684 KB |
Output is correct |
56 |
Correct |
5 ms |
9684 KB |
Output is correct |
57 |
Correct |
109 ms |
25064 KB |
Output is correct |
58 |
Correct |
118 ms |
24972 KB |
Output is correct |
59 |
Correct |
109 ms |
24984 KB |
Output is correct |
60 |
Correct |
110 ms |
24944 KB |
Output is correct |
61 |
Correct |
109 ms |
24900 KB |
Output is correct |
62 |
Correct |
111 ms |
24908 KB |
Output is correct |
63 |
Correct |
109 ms |
24880 KB |
Output is correct |
64 |
Correct |
109 ms |
24744 KB |
Output is correct |
65 |
Correct |
107 ms |
24728 KB |
Output is correct |
66 |
Correct |
109 ms |
24700 KB |
Output is correct |
67 |
Correct |
113 ms |
25032 KB |
Output is correct |
68 |
Correct |
120 ms |
25152 KB |
Output is correct |
69 |
Correct |
114 ms |
25044 KB |
Output is correct |
70 |
Correct |
112 ms |
25016 KB |
Output is correct |
71 |
Correct |
5 ms |
9684 KB |
Output is correct |
72 |
Correct |
7 ms |
10196 KB |
Output is correct |
73 |
Correct |
7 ms |
10144 KB |
Output is correct |
74 |
Correct |
7 ms |
10140 KB |
Output is correct |
75 |
Correct |
7 ms |
10196 KB |
Output is correct |
76 |
Correct |
7 ms |
10196 KB |
Output is correct |
77 |
Correct |
7 ms |
10196 KB |
Output is correct |
78 |
Correct |
7 ms |
10128 KB |
Output is correct |
79 |
Correct |
7 ms |
10176 KB |
Output is correct |
80 |
Correct |
116 ms |
25128 KB |
Output is correct |
81 |
Correct |
112 ms |
24928 KB |
Output is correct |
82 |
Correct |
116 ms |
24824 KB |
Output is correct |
83 |
Correct |
111 ms |
24872 KB |
Output is correct |
84 |
Correct |
7 ms |
10016 KB |
Output is correct |
85 |
Correct |
6 ms |
10068 KB |
Output is correct |
86 |
Correct |
7 ms |
10068 KB |
Output is correct |
87 |
Correct |
7 ms |
10140 KB |
Output is correct |
88 |
Correct |
7 ms |
10068 KB |
Output is correct |
89 |
Correct |
7 ms |
10068 KB |
Output is correct |
90 |
Correct |
7 ms |
10064 KB |
Output is correct |
91 |
Correct |
7 ms |
10196 KB |
Output is correct |
92 |
Correct |
7 ms |
10068 KB |
Output is correct |
93 |
Correct |
7 ms |
10068 KB |
Output is correct |
94 |
Correct |
5 ms |
9684 KB |
Output is correct |
95 |
Correct |
5 ms |
9684 KB |
Output is correct |
96 |
Correct |
4 ms |
9684 KB |
Output is correct |
97 |
Correct |
5 ms |
9684 KB |
Output is correct |
98 |
Correct |
5 ms |
9684 KB |
Output is correct |
99 |
Correct |
5 ms |
9684 KB |
Output is correct |
100 |
Correct |
5 ms |
9684 KB |
Output is correct |
101 |
Correct |
5 ms |
9756 KB |
Output is correct |
102 |
Correct |
5 ms |
9684 KB |
Output is correct |
103 |
Correct |
5 ms |
9684 KB |
Output is correct |
104 |
Correct |
12 ms |
11544 KB |
Output is correct |
105 |
Correct |
22 ms |
14060 KB |
Output is correct |
106 |
Correct |
5 ms |
9684 KB |
Output is correct |
107 |
Correct |
39 ms |
17940 KB |
Output is correct |
108 |
Correct |
52 ms |
21864 KB |
Output is correct |
109 |
Correct |
5 ms |
9812 KB |
Output is correct |
110 |
Correct |
75 ms |
23920 KB |
Output is correct |
111 |
Correct |
89 ms |
26444 KB |
Output is correct |
112 |
Correct |
5 ms |
9812 KB |
Output is correct |
113 |
Correct |
146 ms |
36672 KB |
Output is correct |
114 |
Incorrect |
40 ms |
15852 KB |
Output isn't correct |
115 |
Halted |
0 ms |
0 KB |
- |