답안 #730988

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
730988 2023-04-26T17:40:13 Z rainboy Cheap flights (LMIO18_pigus_skrydziai) C
0 / 100
168 ms 30552 KB
#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--; )
			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--;
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 296 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 296 KB Output is correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 296 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 296 KB Output is correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 28244 KB Output is correct
2 Incorrect 168 ms 30552 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 28244 KB Output is correct
2 Incorrect 168 ms 30552 KB Output isn't correct
3 Halted 0 ms 0 KB -