#include <stdio.h>
#include <stdlib.h>
#define N 300000
long long max(long long a, long long b) { return a > b ? a : b; }
int *ej[N], *ew[N], eo[N];
void append(int i, int j, int w) {
int o = eo[i]++;
if (o >= 2 && (o & o - 1) == 0) {
ej[i] = (int *) realloc(ej[i], o * 2 * sizeof *ej[i]);
ew[i] = (int *) realloc(ew[i], o * 2 * sizeof *ew[i]);
}
ej[i][o] = j, ew[i][o] = w;
}
int main() {
static int ww[N];
int n, m, h, i, j, k, w, w_, o, o_;
long long sum, ans;
scanf("%d%d", &n, &m);
for (i = 0; i < n; i++) {
ej[i] = (int *) malloc(2 * sizeof *ej[i]);
ew[i] = (int *) malloc(2 * sizeof *ew[i]);
}
for (h = 0; h < m; h++) {
scanf("%d%d%d", &i, &j, &w), i--, j--;
append(i, j, w), append(j, i, w);
}
ans = 0;
for (i = 0; i < n; i++) {
sum = 0;
for (o = eo[i]; o--; ) {
j = ej[i][o], w = ew[i][o];
sum += w;
ww[j] = w;
}
ans = max(ans, sum);
for (o = eo[i]; o--; ) {
j = ej[i][o], w = ew[i][o];
if (eo[j] < eo[i] || eo[j] == eo[i] && j < i)
for (o_ = eo[j]; o_--; ) {
k = ej[j][o_], w_ = ew[j][o_];
if (k != i)
ans = max(ans, (long long) w + w_ + ww[k]);
}
}
for (o = eo[i]; o--; ) {
j = ej[i][o];
ww[j] = 0;
}
}
printf("%lld\n", ans);
return 0;
}
Compilation message
pigus_skrydziai.c: In function 'append':
pigus_skrydziai.c:13:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
13 | if (o >= 2 && (o & o - 1) == 0) {
| ~~^~~
pigus_skrydziai.c: In function 'main':
pigus_skrydziai.c:45:40: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
45 | if (eo[j] < eo[i] || eo[j] == eo[i] && j < i)
| ~~~~~~~~~~~~~~~^~~~~~~~
pigus_skrydziai.c:25:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
25 | scanf("%d%d", &n, &m);
| ^~~~~~~~~~~~~~~~~~~~~
pigus_skrydziai.c:31:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | scanf("%d%d%d", &i, &j, &w), i--, j--;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
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 |
11 ms |
980 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 |
0 ms |
352 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
292 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
376 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
11 ms |
980 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 |
0 ms |
352 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
292 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
376 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
384 ms |
20232 KB |
Output is correct |
23 |
Correct |
855 ms |
17104 KB |
Output is correct |
24 |
Correct |
9 ms |
1108 KB |
Output is correct |
25 |
Correct |
4 ms |
596 KB |
Output is correct |
26 |
Correct |
3 ms |
596 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
179 ms |
8560 KB |
Output is correct |
29 |
Correct |
70 ms |
3148 KB |
Output is correct |
30 |
Correct |
124 ms |
4780 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
234 ms |
19044 KB |
Output is correct |
34 |
Correct |
191 ms |
15820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
26080 KB |
Output is correct |
2 |
Correct |
152 ms |
26088 KB |
Output is correct |
3 |
Correct |
43 ms |
10240 KB |
Output is correct |
4 |
Correct |
100 ms |
20688 KB |
Output is correct |
5 |
Correct |
226 ms |
23700 KB |
Output is correct |
6 |
Correct |
115 ms |
3540 KB |
Output is correct |
7 |
Correct |
86 ms |
26132 KB |
Output is correct |
8 |
Correct |
104 ms |
30564 KB |
Output is correct |
9 |
Correct |
19 ms |
26064 KB |
Output is correct |
10 |
Correct |
115 ms |
3604 KB |
Output is correct |
11 |
Correct |
87 ms |
18724 KB |
Output is correct |
12 |
Correct |
223 ms |
6816 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
53 ms |
3864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
26080 KB |
Output is correct |
2 |
Correct |
152 ms |
26088 KB |
Output is correct |
3 |
Correct |
43 ms |
10240 KB |
Output is correct |
4 |
Correct |
100 ms |
20688 KB |
Output is correct |
5 |
Correct |
226 ms |
23700 KB |
Output is correct |
6 |
Correct |
115 ms |
3540 KB |
Output is correct |
7 |
Correct |
86 ms |
26132 KB |
Output is correct |
8 |
Correct |
104 ms |
30564 KB |
Output is correct |
9 |
Correct |
19 ms |
26064 KB |
Output is correct |
10 |
Correct |
115 ms |
3604 KB |
Output is correct |
11 |
Correct |
87 ms |
18724 KB |
Output is correct |
12 |
Correct |
223 ms |
6816 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
53 ms |
3864 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 |
11 ms |
980 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 |
0 ms |
352 KB |
Output is correct |
26 |
Correct |
0 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
292 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
376 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
384 ms |
20232 KB |
Output is correct |
37 |
Correct |
855 ms |
17104 KB |
Output is correct |
38 |
Correct |
9 ms |
1108 KB |
Output is correct |
39 |
Correct |
4 ms |
596 KB |
Output is correct |
40 |
Correct |
3 ms |
596 KB |
Output is correct |
41 |
Correct |
1 ms |
344 KB |
Output is correct |
42 |
Correct |
179 ms |
8560 KB |
Output is correct |
43 |
Correct |
70 ms |
3148 KB |
Output is correct |
44 |
Correct |
124 ms |
4780 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
234 ms |
19044 KB |
Output is correct |
48 |
Correct |
191 ms |
15820 KB |
Output is correct |
49 |
Correct |
88 ms |
10188 KB |
Output is correct |
50 |
Correct |
94 ms |
8932 KB |
Output is correct |
51 |
Correct |
187 ms |
16092 KB |
Output is correct |
52 |
Correct |
204 ms |
12616 KB |
Output is correct |
53 |
Correct |
55 ms |
15640 KB |
Output is correct |
54 |
Correct |
339 ms |
14944 KB |
Output is correct |
55 |
Correct |
186 ms |
33108 KB |
Output is correct |
56 |
Correct |
116 ms |
21952 KB |
Output is correct |
57 |
Correct |
139 ms |
27732 KB |
Output is correct |
58 |
Correct |
59 ms |
7376 KB |
Output is correct |
59 |
Correct |
182 ms |
15080 KB |
Output is correct |
60 |
Correct |
129 ms |
12148 KB |
Output is correct |
61 |
Correct |
131 ms |
10328 KB |
Output is correct |