답안 #945223

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
945223 2024-03-13T14:39:28 Z rainboy Price List (POI13_cen) C
0 / 100
43 ms 21792 KB
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define N	100000
#define M	100000

int *ej[N], *ej_[N], eo[N], eo_[N];

void append(int i, int j) {
	int o = eo[i]++;

	if (o >= 2 && (o & o - 1) == 0)
		ej[i] = (int *) realloc(ej[i], o * 2 * sizeof *ej[i]);
	ej[i][o] = j;
}

int main() {
	static int dd[N], qu1[N], qu2[N];
	static char adj[N];
	int n, m, cnt1, cnt2, s, a, b, h, h1, h2, i, j, k, o, o_, o1;

	scanf("%d%d%d%d%d", &n, &m, &s, &a, &b), s--;
	for (i = 0; i < n; i++)
		ej[i] = (int *) malloc(2 * sizeof *ej[i]);
	for (h = 0; h < m; h++) {
		scanf("%d%d", &i, &j), i--, j--;
		append(i, j), append(j, i);
	}
	for (i = 0; i < n; i++) {
		ej_[i] = (int *) malloc(eo[i] * sizeof *ej_[i]);
		memcpy(ej_[i], ej[i], (eo_[i] = eo[i]) * sizeof *ej[i]);
	}
	memset(dd, 0x3f, n * sizeof *dd);
	cnt1 = cnt2 = 0;
	dd[s] = 0, qu1[cnt1++] = s;
	h1 = 0, h2 = 0;
	while (h1 < cnt1 || h2 < cnt2) {
		i = h2 == cnt2 || h1 < cnt1 && dd[qu1[h1]] < dd[qu2[h2]] ? qu1[h1++] : qu2[h2++];
		adj[i] = 1;
		for (o = eo[i]; o--; ) {
			j = ej[i][o];
			if (dd[j] > dd[i] + a)
				dd[j] = dd[i] + a, qu1[cnt1++] = j;
			adj[j] = 1;
		}
		for (o = eo[i]; o--; ) {
			j = ej[i][o];
			o1 = 0;
			for (o_ = 0; o_ < eo_[j]; o_++) {
				k = ej_[j][o];
				if (adj[k])
					ej_[j][o1++] = k;
				else if (dd[k] > dd[i] + b)
					dd[k] = dd[i] + b, qu2[cnt2++] = k;
			}
			eo_[j] = o1;
		}
		adj[i] = 0;
		for (o = eo[i]; o--; ) {
			j = ej[i][o];
			adj[j] = 0;
		}
	}
	for (i = 0; i < n; i++)
		printf("%d\n", dd[i]);
	return 0;
}

Compilation message

cen.c: In function 'append':
cen.c:13:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   13 |  if (o >= 2 && (o & o - 1) == 0)
      |                     ~~^~~
cen.c: In function 'main':
cen.c:39:31: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   39 |   i = h2 == cnt2 || h1 < cnt1 && dd[qu1[h1]] < dd[qu2[h2]] ? qu1[h1++] : qu2[h2++];
      |                     ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
cen.c:23:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |  scanf("%d%d%d%d%d", &n, &m, &s, &a, &b), s--;
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cen.c:27:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |   scanf("%d%d", &i, &j), i--, j--;
      |   ^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 3672 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 13 ms 11948 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 24 ms 9344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 25 ms 19536 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 28 ms 21792 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 43 ms 11392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 38 ms 11880 KB Output isn't correct
2 Halted 0 ms 0 KB -