#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;
vector<ll> ws(N);
for(int i = 0; i < E; i++) {
int U, V, P;
cin >> U >> V >> P;
--U, --V;
ws[U] += P;
ws[V] += P;
adj[U].push_back(V);
adj[V].push_back(U);
w.setW(U, V, P);
}
ll ans = *max_element(ws.begin(), ws.end());
for(int u = 0; u < N; u++) {
for(int j = 0; j < (int)adj[u].size() - 1; j++) {
int v = adj[u][j], r = adj[u][j + 1];
if(w.count(v, r)) {
ans = max(ans, (ll)w.getW(u,v) + (ll)w.getW(v,r) + (ll)w.getW(u,r));
}
}
}
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 |
21 ms |
1792 KB |
Output is correct |
7 |
Correct |
1 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 |
1 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 |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 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 |
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 |
1 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 |
21 ms |
1792 KB |
Output is correct |
7 |
Correct |
1 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 |
1 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 |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 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 |
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 |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1314 ms |
37312 KB |
Output is correct |
23 |
Correct |
949 ms |
35660 KB |
Output is correct |
24 |
Correct |
17 ms |
1912 KB |
Output is correct |
25 |
Correct |
6 ms |
840 KB |
Output is correct |
26 |
Correct |
5 ms |
848 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
256 ms |
14992 KB |
Output is correct |
29 |
Correct |
182 ms |
6220 KB |
Output is correct |
30 |
Correct |
262 ms |
9284 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
326 ms |
36392 KB |
Output is correct |
34 |
Correct |
265 ms |
33444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
192 ms |
28420 KB |
Output is correct |
2 |
Correct |
459 ms |
37920 KB |
Output is correct |
3 |
Correct |
119 ms |
12748 KB |
Output is correct |
4 |
Correct |
250 ms |
25188 KB |
Output is correct |
5 |
Correct |
643 ms |
32212 KB |
Output is correct |
6 |
Correct |
192 ms |
9292 KB |
Output is correct |
7 |
Correct |
171 ms |
32360 KB |
Output is correct |
8 |
Correct |
228 ms |
37764 KB |
Output is correct |
9 |
Correct |
7 ms |
9736 KB |
Output is correct |
10 |
Correct |
202 ms |
9224 KB |
Output is correct |
11 |
Correct |
170 ms |
29668 KB |
Output is correct |
12 |
Correct |
139 ms |
18084 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
141 ms |
7756 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
192 ms |
28420 KB |
Output is correct |
2 |
Correct |
459 ms |
37920 KB |
Output is correct |
3 |
Correct |
119 ms |
12748 KB |
Output is correct |
4 |
Correct |
250 ms |
25188 KB |
Output is correct |
5 |
Correct |
643 ms |
32212 KB |
Output is correct |
6 |
Correct |
192 ms |
9292 KB |
Output is correct |
7 |
Correct |
171 ms |
32360 KB |
Output is correct |
8 |
Correct |
228 ms |
37764 KB |
Output is correct |
9 |
Correct |
7 ms |
9736 KB |
Output is correct |
10 |
Correct |
202 ms |
9224 KB |
Output is correct |
11 |
Correct |
170 ms |
29668 KB |
Output is correct |
12 |
Correct |
139 ms |
18084 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
141 ms |
7756 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 |
21 ms |
1792 KB |
Output is correct |
21 |
Correct |
1 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 |
1 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 |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1314 ms |
37312 KB |
Output is correct |
37 |
Correct |
949 ms |
35660 KB |
Output is correct |
38 |
Correct |
17 ms |
1912 KB |
Output is correct |
39 |
Correct |
6 ms |
840 KB |
Output is correct |
40 |
Correct |
5 ms |
848 KB |
Output is correct |
41 |
Correct |
2 ms |
468 KB |
Output is correct |
42 |
Correct |
256 ms |
14992 KB |
Output is correct |
43 |
Correct |
182 ms |
6220 KB |
Output is correct |
44 |
Correct |
262 ms |
9284 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
326 ms |
36392 KB |
Output is correct |
48 |
Correct |
265 ms |
33444 KB |
Output is correct |
49 |
Correct |
218 ms |
17772 KB |
Output is correct |
50 |
Correct |
275 ms |
15596 KB |
Output is correct |
51 |
Correct |
459 ms |
22140 KB |
Output is correct |
52 |
Correct |
541 ms |
22340 KB |
Output is correct |
53 |
Correct |
116 ms |
14688 KB |
Output is correct |
54 |
Correct |
567 ms |
23400 KB |
Output is correct |
55 |
Correct |
490 ms |
37860 KB |
Output is correct |
56 |
Correct |
265 ms |
25280 KB |
Output is correct |
57 |
Correct |
404 ms |
32304 KB |
Output is correct |
58 |
Correct |
159 ms |
13384 KB |
Output is correct |
59 |
Correct |
610 ms |
25124 KB |
Output is correct |
60 |
Correct |
446 ms |
24748 KB |
Output is correct |
61 |
Correct |
510 ms |
22152 KB |
Output is correct |