#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int maxn = 3e5 + 5;
map<ii, int> cost;
int N, M;
vector<ii> adj[maxn];
signed main(void)
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL
freopen("A.INP", "r", stdin);
freopen("A.OUT", "w", stdout);
#endif // LOCAL
cin >> N >> M;
ll res = 0;
while(M--){
int u, v, w;
cin >> u >> v >> w;
cost[mp(u, v)] = cost[mp(v, u)] = w;
adj[u].eb(w, v); adj[v].eb(w, u);
}
for(int i = 1; i <= N; ++i){
sort(adj[i].rbegin(), adj[i].rend());
ll sum = 0;
for(auto & it : adj[i]) sum += it.fi;
if(adj[i].size() >= 2 && cost[mp(adj[i][0].se, adj[i][1].se)])
res = max(res, 1ll * adj[i][0].fi + adj[i][1].fi + cost[mp(adj[i][0].se, adj[i][1].se)]);
res = max(res, sum);
}
cout << res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
7424 KB |
Output is correct |
2 |
Correct |
8 ms |
7296 KB |
Output is correct |
3 |
Correct |
8 ms |
7424 KB |
Output is correct |
4 |
Correct |
8 ms |
7296 KB |
Output is correct |
5 |
Correct |
9 ms |
7296 KB |
Output is correct |
6 |
Correct |
28 ms |
10496 KB |
Output is correct |
7 |
Correct |
9 ms |
7424 KB |
Output is correct |
8 |
Correct |
8 ms |
7424 KB |
Output is correct |
9 |
Correct |
9 ms |
7424 KB |
Output is correct |
10 |
Correct |
9 ms |
7424 KB |
Output is correct |
11 |
Correct |
9 ms |
7424 KB |
Output is correct |
12 |
Correct |
9 ms |
7424 KB |
Output is correct |
13 |
Correct |
9 ms |
7424 KB |
Output is correct |
14 |
Correct |
8 ms |
7424 KB |
Output is correct |
15 |
Correct |
9 ms |
7424 KB |
Output is correct |
16 |
Correct |
8 ms |
7424 KB |
Output is correct |
17 |
Correct |
9 ms |
7424 KB |
Output is correct |
18 |
Correct |
9 ms |
7552 KB |
Output is correct |
19 |
Correct |
10 ms |
7680 KB |
Output is correct |
20 |
Correct |
8 ms |
7424 KB |
Output is correct |
21 |
Correct |
9 ms |
7424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
7424 KB |
Output is correct |
2 |
Correct |
8 ms |
7296 KB |
Output is correct |
3 |
Correct |
8 ms |
7424 KB |
Output is correct |
4 |
Correct |
8 ms |
7296 KB |
Output is correct |
5 |
Correct |
9 ms |
7296 KB |
Output is correct |
6 |
Correct |
28 ms |
10496 KB |
Output is correct |
7 |
Correct |
9 ms |
7424 KB |
Output is correct |
8 |
Correct |
8 ms |
7424 KB |
Output is correct |
9 |
Correct |
9 ms |
7424 KB |
Output is correct |
10 |
Correct |
9 ms |
7424 KB |
Output is correct |
11 |
Correct |
9 ms |
7424 KB |
Output is correct |
12 |
Correct |
9 ms |
7424 KB |
Output is correct |
13 |
Correct |
9 ms |
7424 KB |
Output is correct |
14 |
Correct |
8 ms |
7424 KB |
Output is correct |
15 |
Correct |
9 ms |
7424 KB |
Output is correct |
16 |
Correct |
8 ms |
7424 KB |
Output is correct |
17 |
Correct |
9 ms |
7424 KB |
Output is correct |
18 |
Correct |
9 ms |
7552 KB |
Output is correct |
19 |
Correct |
10 ms |
7680 KB |
Output is correct |
20 |
Correct |
8 ms |
7424 KB |
Output is correct |
21 |
Correct |
9 ms |
7424 KB |
Output is correct |
22 |
Correct |
1561 ms |
89544 KB |
Output is correct |
23 |
Correct |
560 ms |
86776 KB |
Output is correct |
24 |
Correct |
37 ms |
10872 KB |
Output is correct |
25 |
Correct |
15 ms |
8448 KB |
Output is correct |
26 |
Correct |
14 ms |
8448 KB |
Output is correct |
27 |
Correct |
11 ms |
7808 KB |
Output is correct |
28 |
Correct |
456 ms |
40040 KB |
Output is correct |
29 |
Correct |
147 ms |
20216 KB |
Output is correct |
30 |
Correct |
252 ms |
27256 KB |
Output is correct |
31 |
Correct |
9 ms |
7552 KB |
Output is correct |
32 |
Correct |
9 ms |
7552 KB |
Output is correct |
33 |
Correct |
605 ms |
87416 KB |
Output is correct |
34 |
Correct |
473 ms |
78668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
309 ms |
37752 KB |
Output is correct |
2 |
Correct |
781 ms |
77816 KB |
Output is correct |
3 |
Correct |
209 ms |
30680 KB |
Output is correct |
4 |
Correct |
461 ms |
52240 KB |
Output is correct |
5 |
Correct |
1155 ms |
69384 KB |
Output is correct |
6 |
Correct |
120 ms |
26232 KB |
Output is correct |
7 |
Correct |
292 ms |
61948 KB |
Output is correct |
8 |
Correct |
321 ms |
58872 KB |
Output is correct |
9 |
Correct |
11 ms |
7552 KB |
Output is correct |
10 |
Correct |
112 ms |
26360 KB |
Output is correct |
11 |
Correct |
320 ms |
55020 KB |
Output is correct |
12 |
Correct |
238 ms |
45176 KB |
Output is correct |
13 |
Correct |
9 ms |
7424 KB |
Output is correct |
14 |
Correct |
199 ms |
23288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
309 ms |
37752 KB |
Output is correct |
2 |
Correct |
781 ms |
77816 KB |
Output is correct |
3 |
Correct |
209 ms |
30680 KB |
Output is correct |
4 |
Correct |
461 ms |
52240 KB |
Output is correct |
5 |
Correct |
1155 ms |
69384 KB |
Output is correct |
6 |
Correct |
120 ms |
26232 KB |
Output is correct |
7 |
Correct |
292 ms |
61948 KB |
Output is correct |
8 |
Correct |
321 ms |
58872 KB |
Output is correct |
9 |
Correct |
11 ms |
7552 KB |
Output is correct |
10 |
Correct |
112 ms |
26360 KB |
Output is correct |
11 |
Correct |
320 ms |
55020 KB |
Output is correct |
12 |
Correct |
238 ms |
45176 KB |
Output is correct |
13 |
Correct |
9 ms |
7424 KB |
Output is correct |
14 |
Correct |
199 ms |
23288 KB |
Output is correct |
15 |
Correct |
499 ms |
41180 KB |
Output is correct |
16 |
Correct |
483 ms |
40312 KB |
Output is correct |
17 |
Correct |
533 ms |
45544 KB |
Output is correct |
18 |
Correct |
767 ms |
53972 KB |
Output is correct |
19 |
Correct |
199 ms |
25576 KB |
Output is correct |
20 |
Correct |
764 ms |
58744 KB |
Output is correct |
21 |
Correct |
763 ms |
80196 KB |
Output is correct |
22 |
Correct |
491 ms |
55672 KB |
Output is correct |
23 |
Correct |
581 ms |
55528 KB |
Output is correct |
24 |
Correct |
337 ms |
32352 KB |
Output is correct |
25 |
Correct |
901 ms |
60216 KB |
Output is correct |
26 |
Correct |
806 ms |
55128 KB |
Output is correct |
27 |
Correct |
750 ms |
53240 KB |
Output is correct |
28 |
Correct |
8 ms |
7424 KB |
Output is correct |
29 |
Correct |
8 ms |
7296 KB |
Output is correct |
30 |
Correct |
8 ms |
7424 KB |
Output is correct |
31 |
Correct |
8 ms |
7296 KB |
Output is correct |
32 |
Correct |
9 ms |
7296 KB |
Output is correct |
33 |
Correct |
28 ms |
10496 KB |
Output is correct |
34 |
Correct |
9 ms |
7424 KB |
Output is correct |
35 |
Correct |
8 ms |
7424 KB |
Output is correct |
36 |
Correct |
9 ms |
7424 KB |
Output is correct |
37 |
Correct |
9 ms |
7424 KB |
Output is correct |
38 |
Correct |
9 ms |
7424 KB |
Output is correct |
39 |
Correct |
9 ms |
7424 KB |
Output is correct |
40 |
Correct |
9 ms |
7424 KB |
Output is correct |
41 |
Correct |
8 ms |
7424 KB |
Output is correct |
42 |
Correct |
9 ms |
7424 KB |
Output is correct |
43 |
Correct |
8 ms |
7424 KB |
Output is correct |
44 |
Correct |
9 ms |
7424 KB |
Output is correct |
45 |
Correct |
9 ms |
7552 KB |
Output is correct |
46 |
Correct |
10 ms |
7680 KB |
Output is correct |
47 |
Correct |
8 ms |
7424 KB |
Output is correct |
48 |
Correct |
9 ms |
7424 KB |
Output is correct |
49 |
Correct |
1561 ms |
89544 KB |
Output is correct |
50 |
Correct |
560 ms |
86776 KB |
Output is correct |
51 |
Correct |
37 ms |
10872 KB |
Output is correct |
52 |
Correct |
15 ms |
8448 KB |
Output is correct |
53 |
Correct |
14 ms |
8448 KB |
Output is correct |
54 |
Correct |
11 ms |
7808 KB |
Output is correct |
55 |
Correct |
456 ms |
40040 KB |
Output is correct |
56 |
Correct |
147 ms |
20216 KB |
Output is correct |
57 |
Correct |
252 ms |
27256 KB |
Output is correct |
58 |
Correct |
9 ms |
7552 KB |
Output is correct |
59 |
Correct |
9 ms |
7552 KB |
Output is correct |
60 |
Correct |
605 ms |
87416 KB |
Output is correct |
61 |
Correct |
473 ms |
78668 KB |
Output is correct |