#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007
using namespace std;
struct weight {
map<pair<int,int>, int> w;
void setW(int u, int v, int p) {
if(u > v) swap(u,v);
w[{u,v}] = p;
}
int getW(int u, int v) {
if(u > v) swap(u, v);
return w[{u,v}];
}
int count(int u, int v) {
if(u > v) swap(u, v);
return w.count({u,v});
}
};
void solve() {
int N, E; cin >> N >> E;
vector<int> adj[N];
weight w;
for(int i = 0; i < E; i++) {
int U, V, P;
cin >> U >> V >> P;
--U, --V;
adj[U].push_back(V);
adj[V].push_back(U);
w.setW(U, V, P);
}
ll ans = 0LL;
for(int u = 0; u < N; u++) {
ll tmp = adj[u].size() ? (ll)w.getW(u, adj[u][0]) : 0LL;
for(int j = 0; j < (int)adj[u].size() - 1; j++) {
int v = adj[u][j], r = adj[u][j + 1];
tmp += (ll)w.getW(u, r);
if(w.count(v, r)) {
ans = max(ans, (ll)w.getW(u,v) + (ll)w.getW(v,r) + (ll)w.getW(u,r));
}
}
ans = max(ans, tmp);
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int test_cases = 1;
// cin >> test_cases;
for(int test_case = 1; test_case <= test_cases; test_case++) {
// cout << "Case #" << test_case << ": ";
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
26 ms |
1916 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
26 ms |
1916 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1681 ms |
37276 KB |
Output is correct |
23 |
Correct |
1170 ms |
35768 KB |
Output is correct |
24 |
Correct |
23 ms |
1888 KB |
Output is correct |
25 |
Correct |
6 ms |
724 KB |
Output is correct |
26 |
Correct |
6 ms |
724 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
466 ms |
14912 KB |
Output is correct |
29 |
Correct |
204 ms |
6220 KB |
Output is correct |
30 |
Correct |
340 ms |
9192 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
698 ms |
36400 KB |
Output is correct |
34 |
Correct |
597 ms |
33496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
270 ms |
26120 KB |
Output is correct |
2 |
Correct |
531 ms |
35520 KB |
Output is correct |
3 |
Correct |
153 ms |
12036 KB |
Output is correct |
4 |
Correct |
299 ms |
23488 KB |
Output is correct |
5 |
Correct |
841 ms |
30648 KB |
Output is correct |
6 |
Correct |
241 ms |
9200 KB |
Output is correct |
7 |
Correct |
211 ms |
30456 KB |
Output is correct |
8 |
Correct |
271 ms |
35520 KB |
Output is correct |
9 |
Correct |
15 ms |
7380 KB |
Output is correct |
10 |
Correct |
318 ms |
9216 KB |
Output is correct |
11 |
Correct |
268 ms |
28500 KB |
Output is correct |
12 |
Correct |
235 ms |
18304 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
178 ms |
7804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
270 ms |
26120 KB |
Output is correct |
2 |
Correct |
531 ms |
35520 KB |
Output is correct |
3 |
Correct |
153 ms |
12036 KB |
Output is correct |
4 |
Correct |
299 ms |
23488 KB |
Output is correct |
5 |
Correct |
841 ms |
30648 KB |
Output is correct |
6 |
Correct |
241 ms |
9200 KB |
Output is correct |
7 |
Correct |
211 ms |
30456 KB |
Output is correct |
8 |
Correct |
271 ms |
35520 KB |
Output is correct |
9 |
Correct |
15 ms |
7380 KB |
Output is correct |
10 |
Correct |
318 ms |
9216 KB |
Output is correct |
11 |
Correct |
268 ms |
28500 KB |
Output is correct |
12 |
Correct |
235 ms |
18304 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
178 ms |
7804 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
26 ms |
1916 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
2 ms |
468 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
1681 ms |
37276 KB |
Output is correct |
37 |
Correct |
1170 ms |
35768 KB |
Output is correct |
38 |
Correct |
23 ms |
1888 KB |
Output is correct |
39 |
Correct |
6 ms |
724 KB |
Output is correct |
40 |
Correct |
6 ms |
724 KB |
Output is correct |
41 |
Correct |
2 ms |
468 KB |
Output is correct |
42 |
Correct |
466 ms |
14912 KB |
Output is correct |
43 |
Correct |
204 ms |
6220 KB |
Output is correct |
44 |
Correct |
340 ms |
9192 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
698 ms |
36400 KB |
Output is correct |
48 |
Correct |
597 ms |
33496 KB |
Output is correct |
49 |
Correct |
365 ms |
17300 KB |
Output is correct |
50 |
Correct |
321 ms |
15500 KB |
Output is correct |
51 |
Correct |
538 ms |
21296 KB |
Output is correct |
52 |
Correct |
673 ms |
22088 KB |
Output is correct |
53 |
Correct |
135 ms |
13400 KB |
Output is correct |
54 |
Correct |
710 ms |
23468 KB |
Output is correct |
55 |
Correct |
531 ms |
35520 KB |
Output is correct |
56 |
Correct |
301 ms |
23856 KB |
Output is correct |
57 |
Correct |
446 ms |
30328 KB |
Output is correct |
58 |
Correct |
242 ms |
13032 KB |
Output is correct |
59 |
Correct |
711 ms |
24848 KB |
Output is correct |
60 |
Correct |
587 ms |
24452 KB |
Output is correct |
61 |
Correct |
623 ms |
22220 KB |
Output is correct |