#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});
}
};
const int mxN = (int)3e5;
vector<int> adj[mxN];
weight w;
void solve() {
int N, E; cin >> N >> E;
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());
set<set<int>> cycles;
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7252 KB |
Output is correct |
2 |
Correct |
3 ms |
7252 KB |
Output is correct |
3 |
Correct |
4 ms |
7252 KB |
Output is correct |
4 |
Correct |
4 ms |
7252 KB |
Output is correct |
5 |
Correct |
4 ms |
7252 KB |
Output is correct |
6 |
Correct |
25 ms |
8788 KB |
Output is correct |
7 |
Correct |
4 ms |
7252 KB |
Output is correct |
8 |
Correct |
4 ms |
7364 KB |
Output is correct |
9 |
Correct |
5 ms |
7344 KB |
Output is correct |
10 |
Correct |
4 ms |
7252 KB |
Output is correct |
11 |
Correct |
5 ms |
7368 KB |
Output is correct |
12 |
Correct |
5 ms |
7368 KB |
Output is correct |
13 |
Correct |
4 ms |
7380 KB |
Output is correct |
14 |
Correct |
4 ms |
7252 KB |
Output is correct |
15 |
Correct |
6 ms |
7252 KB |
Output is correct |
16 |
Correct |
4 ms |
7276 KB |
Output is correct |
17 |
Correct |
4 ms |
7252 KB |
Output is correct |
18 |
Correct |
5 ms |
7372 KB |
Output is correct |
19 |
Correct |
5 ms |
7508 KB |
Output is correct |
20 |
Correct |
4 ms |
7368 KB |
Output is correct |
21 |
Correct |
4 ms |
7368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7252 KB |
Output is correct |
2 |
Correct |
3 ms |
7252 KB |
Output is correct |
3 |
Correct |
4 ms |
7252 KB |
Output is correct |
4 |
Correct |
4 ms |
7252 KB |
Output is correct |
5 |
Correct |
4 ms |
7252 KB |
Output is correct |
6 |
Correct |
25 ms |
8788 KB |
Output is correct |
7 |
Correct |
4 ms |
7252 KB |
Output is correct |
8 |
Correct |
4 ms |
7364 KB |
Output is correct |
9 |
Correct |
5 ms |
7344 KB |
Output is correct |
10 |
Correct |
4 ms |
7252 KB |
Output is correct |
11 |
Correct |
5 ms |
7368 KB |
Output is correct |
12 |
Correct |
5 ms |
7368 KB |
Output is correct |
13 |
Correct |
4 ms |
7380 KB |
Output is correct |
14 |
Correct |
4 ms |
7252 KB |
Output is correct |
15 |
Correct |
6 ms |
7252 KB |
Output is correct |
16 |
Correct |
4 ms |
7276 KB |
Output is correct |
17 |
Correct |
4 ms |
7252 KB |
Output is correct |
18 |
Correct |
5 ms |
7372 KB |
Output is correct |
19 |
Correct |
5 ms |
7508 KB |
Output is correct |
20 |
Correct |
4 ms |
7368 KB |
Output is correct |
21 |
Correct |
4 ms |
7368 KB |
Output is correct |
22 |
Correct |
1218 ms |
52788 KB |
Output is correct |
23 |
Correct |
970 ms |
51428 KB |
Output is correct |
24 |
Correct |
21 ms |
9172 KB |
Output is correct |
25 |
Correct |
8 ms |
7892 KB |
Output is correct |
26 |
Correct |
8 ms |
7892 KB |
Output is correct |
27 |
Correct |
5 ms |
7508 KB |
Output is correct |
28 |
Correct |
274 ms |
25496 KB |
Output is correct |
29 |
Correct |
157 ms |
14280 KB |
Output is correct |
30 |
Correct |
296 ms |
18392 KB |
Output is correct |
31 |
Correct |
4 ms |
7380 KB |
Output is correct |
32 |
Correct |
4 ms |
7376 KB |
Output is correct |
33 |
Correct |
351 ms |
51352 KB |
Output is correct |
34 |
Correct |
285 ms |
45644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
172 ms |
28492 KB |
Output is correct |
2 |
Correct |
488 ms |
37868 KB |
Output is correct |
3 |
Correct |
104 ms |
17520 KB |
Output is correct |
4 |
Correct |
246 ms |
27432 KB |
Output is correct |
5 |
Correct |
664 ms |
34536 KB |
Output is correct |
6 |
Correct |
187 ms |
16248 KB |
Output is correct |
7 |
Correct |
176 ms |
37256 KB |
Output is correct |
8 |
Correct |
262 ms |
42312 KB |
Output is correct |
9 |
Correct |
7 ms |
9812 KB |
Output is correct |
10 |
Correct |
187 ms |
17560 KB |
Output is correct |
11 |
Correct |
183 ms |
36364 KB |
Output is correct |
12 |
Correct |
142 ms |
27492 KB |
Output is correct |
13 |
Correct |
4 ms |
7252 KB |
Output is correct |
14 |
Correct |
120 ms |
15820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
172 ms |
28492 KB |
Output is correct |
2 |
Correct |
488 ms |
37868 KB |
Output is correct |
3 |
Correct |
104 ms |
17520 KB |
Output is correct |
4 |
Correct |
246 ms |
27432 KB |
Output is correct |
5 |
Correct |
664 ms |
34536 KB |
Output is correct |
6 |
Correct |
187 ms |
16248 KB |
Output is correct |
7 |
Correct |
176 ms |
37256 KB |
Output is correct |
8 |
Correct |
262 ms |
42312 KB |
Output is correct |
9 |
Correct |
7 ms |
9812 KB |
Output is correct |
10 |
Correct |
187 ms |
17560 KB |
Output is correct |
11 |
Correct |
183 ms |
36364 KB |
Output is correct |
12 |
Correct |
142 ms |
27492 KB |
Output is correct |
13 |
Correct |
4 ms |
7252 KB |
Output is correct |
14 |
Correct |
120 ms |
15820 KB |
Output is correct |
15 |
Correct |
4 ms |
7252 KB |
Output is correct |
16 |
Correct |
3 ms |
7252 KB |
Output is correct |
17 |
Correct |
4 ms |
7252 KB |
Output is correct |
18 |
Correct |
4 ms |
7252 KB |
Output is correct |
19 |
Correct |
4 ms |
7252 KB |
Output is correct |
20 |
Correct |
25 ms |
8788 KB |
Output is correct |
21 |
Correct |
4 ms |
7252 KB |
Output is correct |
22 |
Correct |
4 ms |
7364 KB |
Output is correct |
23 |
Correct |
5 ms |
7344 KB |
Output is correct |
24 |
Correct |
4 ms |
7252 KB |
Output is correct |
25 |
Correct |
5 ms |
7368 KB |
Output is correct |
26 |
Correct |
5 ms |
7368 KB |
Output is correct |
27 |
Correct |
4 ms |
7380 KB |
Output is correct |
28 |
Correct |
4 ms |
7252 KB |
Output is correct |
29 |
Correct |
6 ms |
7252 KB |
Output is correct |
30 |
Correct |
4 ms |
7276 KB |
Output is correct |
31 |
Correct |
4 ms |
7252 KB |
Output is correct |
32 |
Correct |
5 ms |
7372 KB |
Output is correct |
33 |
Correct |
5 ms |
7508 KB |
Output is correct |
34 |
Correct |
4 ms |
7368 KB |
Output is correct |
35 |
Correct |
4 ms |
7368 KB |
Output is correct |
36 |
Correct |
1218 ms |
52788 KB |
Output is correct |
37 |
Correct |
970 ms |
51428 KB |
Output is correct |
38 |
Correct |
21 ms |
9172 KB |
Output is correct |
39 |
Correct |
8 ms |
7892 KB |
Output is correct |
40 |
Correct |
8 ms |
7892 KB |
Output is correct |
41 |
Correct |
5 ms |
7508 KB |
Output is correct |
42 |
Correct |
274 ms |
25496 KB |
Output is correct |
43 |
Correct |
157 ms |
14280 KB |
Output is correct |
44 |
Correct |
296 ms |
18392 KB |
Output is correct |
45 |
Correct |
4 ms |
7380 KB |
Output is correct |
46 |
Correct |
4 ms |
7376 KB |
Output is correct |
47 |
Correct |
351 ms |
51352 KB |
Output is correct |
48 |
Correct |
285 ms |
45644 KB |
Output is correct |
49 |
Correct |
248 ms |
25852 KB |
Output is correct |
50 |
Correct |
244 ms |
26172 KB |
Output is correct |
51 |
Correct |
478 ms |
30788 KB |
Output is correct |
52 |
Correct |
568 ms |
33316 KB |
Output is correct |
53 |
Correct |
116 ms |
20036 KB |
Output is correct |
54 |
Correct |
579 ms |
35636 KB |
Output is correct |
55 |
Correct |
469 ms |
44948 KB |
Output is correct |
56 |
Correct |
278 ms |
32076 KB |
Output is correct |
57 |
Correct |
376 ms |
37824 KB |
Output is correct |
58 |
Correct |
155 ms |
20672 KB |
Output is correct |
59 |
Correct |
610 ms |
35972 KB |
Output is correct |
60 |
Correct |
456 ms |
34448 KB |
Output is correct |
61 |
Correct |
563 ms |
32412 KB |
Output is correct |