結果

問題 No.1382 Travel in Mitaru city
ユーザー 👑 ygussanyygussany
提出日時 2021-02-07 20:57:57
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 1,593 bytes
コンパイル時間 573 ms
コンパイル使用メモリ 29,252 KB
実行使用メモリ 7,376 KB
最終ジャッジ日時 2023-09-17 19:48:35
合計ジャッジ時間 5,675 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
5,952 KB
testcase_03 AC 2 ms
4,628 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
5,048 KB
testcase_06 AC 27 ms
6,664 KB
testcase_07 AC 23 ms
5,976 KB
testcase_08 AC 11 ms
5,220 KB
testcase_09 AC 30 ms
6,776 KB
testcase_10 AC 28 ms
6,728 KB
testcase_11 AC 39 ms
5,840 KB
testcase_12 AC 39 ms
6,408 KB
testcase_13 AC 41 ms
6,484 KB
testcase_14 AC 35 ms
6,808 KB
testcase_15 AC 35 ms
6,380 KB
testcase_16 AC 58 ms
7,224 KB
testcase_17 AC 59 ms
6,996 KB
testcase_18 AC 58 ms
6,976 KB
testcase_19 AC 58 ms
7,260 KB
testcase_20 AC 57 ms
7,092 KB
testcase_21 AC 59 ms
6,972 KB
testcase_22 AC 63 ms
7,300 KB
testcase_23 AC 59 ms
7,272 KB
testcase_24 AC 60 ms
7,292 KB
testcase_25 AC 57 ms
7,288 KB
testcase_26 AC 50 ms
7,236 KB
testcase_27 AC 51 ms
7,344 KB
testcase_28 AC 50 ms
7,300 KB
testcase_29 AC 48 ms
7,364 KB
testcase_30 AC 46 ms
7,316 KB
testcase_31 AC 36 ms
6,832 KB
testcase_32 AC 45 ms
7,376 KB
testcase_33 AC 41 ms
6,936 KB
testcase_34 AC 28 ms
6,152 KB
testcase_35 AC 18 ms
6,552 KB
testcase_36 AC 30 ms
6,568 KB
testcase_37 AC 5 ms
4,380 KB
testcase_38 AC 33 ms
6,748 KB
testcase_39 AC 9 ms
4,716 KB
testcase_40 AC 26 ms
6,348 KB
testcase_41 AC 28 ms
6,704 KB
testcase_42 AC 33 ms
6,996 KB
testcase_43 AC 30 ms
6,508 KB
testcase_44 AC 13 ms
6,084 KB
testcase_45 AC 27 ms
6,500 KB
testcase_46 AC 13 ms
5,036 KB
testcase_47 AC 48 ms
7,008 KB
testcase_48 AC 35 ms
5,984 KB
testcase_49 AC 54 ms
7,072 KB
testcase_50 AC 23 ms
6,100 KB
testcase_51 AC 35 ms
6,504 KB
testcase_52 AC 43 ms
7,192 KB
testcase_53 AC 9 ms
5,964 KB
testcase_54 AC 18 ms
6,624 KB
testcase_55 AC 41 ms
7,232 KB
testcase_56 AC 14 ms
5,256 KB
testcase_57 AC 26 ms
6,632 KB
testcase_58 AC 5 ms
4,380 KB
testcase_59 AC 12 ms
5,188 KB
testcase_60 AC 39 ms
7,072 KB
testcase_61 AC 3 ms
4,396 KB
testcase_62 AC 2 ms
4,376 KB
testcase_63 AC 8 ms
5,152 KB
testcase_64 AC 3 ms
4,392 KB
testcase_65 AC 2 ms
4,380 KB
testcase_66 AC 3 ms
4,580 KB
testcase_67 AC 3 ms
4,396 KB
testcase_68 AC 4 ms
5,048 KB
testcase_69 AC 3 ms
4,800 KB
testcase_70 AC 4 ms
4,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

typedef struct {
	int key, id;
} data;

typedef struct {
	data obj[100001];
	int size;
} max_heap;

void push(data x, max_heap* h)
{
	int i = ++(h->size), j = i >> 1;
	data tmp;
	h->obj[i] = x;
	while (j > 0) {
		if (h->obj[i].key > h->obj[j].key) {
			tmp = h->obj[j];
			h->obj[j] = h->obj[i];
			h->obj[i] = tmp;
			i = j;
			j >>= 1;
		} else break;
	}
}

data pop(max_heap* h)
{
	int i = 1, j = 2;
	data output = h->obj[1], tmp;
	h->obj[1] = h->obj[(h->size)--];
	while (j <= h->size) {
		if (j < h->size && h->obj[j^1].key > h->obj[j].key) j ^= 1;
		if (h->obj[j].key > h->obj[i].key) {
			tmp = h->obj[j];
			h->obj[j] = h->obj[i];
			h->obj[i] = tmp;
			i = j;
			j <<= 1;
		} else break;
	}
	return output;
}

typedef struct List {
	struct List *next;
	int v;
} list;

int main()
{
	int i, N, M, S, T, u, w, P[100001];
	list *adj[100001] = {}, e[200001], *p;
	scanf("%d %d %d %d", &N, &M, &S, &T);
	for (i = 1; i <= N; i++) scanf("%d", &(P[i]));
	for (i = 0; i < M; i++) {
		scanf("%d %d", &u, &w);
		e[i*2].v = w;
		e[i*2+1].v = u;
		e[i*2].next = adj[u];
		e[i*2+1].next = adj[w];
		adj[u] = &(e[i*2]);
		adj[w] = &(e[i*2+1]);
	}
	
	int X = P[S], Y = 0, flag[100001] = {};
	max_heap h;
	data d;
	h.size = 0;
	d.key = P[S];
	d.id = S;
	push(d, &h);
	flag[S] = 1;
	while (h.size > 0) {
		d = pop(&h);
		u = d.id;
		if (X > P[u]) {
			X = P[u];
			Y++;
		}
		for (p = adj[u]; p != NULL; p = p->next) {
			w = p->v;
			if (flag[w] == 0) {
				flag[w] = 1;
				d.key = P[w];
				d.id = w;
				push(d, &h);
			}
		}
	}
	printf("%d\n", Y);
	fflush(stdout);
	return 0;
}
0