結果

問題 No.1898 Battle and Exchange
ユーザー 👑 ygussanyygussany
提出日時 2022-03-20 11:02:25
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 780 ms / 5,000 ms
コード長 2,809 bytes
コンパイル時間 330 ms
コンパイル使用メモリ 32,740 KB
実行使用メモリ 8,064 KB
最終ジャッジ日時 2024-04-16 02:40:41
合計ジャッジ時間 17,387 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 12 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 9 ms
5,376 KB
testcase_18 AC 59 ms
5,376 KB
testcase_19 AC 115 ms
5,376 KB
testcase_20 AC 54 ms
5,376 KB
testcase_21 AC 270 ms
7,296 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 6 ms
5,376 KB
testcase_28 AC 10 ms
5,376 KB
testcase_29 AC 29 ms
5,376 KB
testcase_30 AC 3 ms
5,376 KB
testcase_31 AC 1 ms
5,376 KB
testcase_32 AC 73 ms
5,376 KB
testcase_33 AC 201 ms
5,504 KB
testcase_34 AC 77 ms
5,376 KB
testcase_35 AC 132 ms
5,376 KB
testcase_36 AC 91 ms
5,376 KB
testcase_37 AC 41 ms
5,376 KB
testcase_38 AC 351 ms
8,064 KB
testcase_39 AC 86 ms
6,912 KB
testcase_40 AC 780 ms
7,424 KB
testcase_41 AC 64 ms
6,528 KB
testcase_42 AC 12 ms
5,376 KB
testcase_43 AC 93 ms
6,016 KB
testcase_44 AC 2 ms
5,376 KB
testcase_45 AC 34 ms
5,376 KB
testcase_46 AC 133 ms
5,376 KB
testcase_47 AC 23 ms
5,376 KB
testcase_48 AC 12 ms
5,376 KB
testcase_49 AC 7 ms
5,376 KB
testcase_50 AC 6 ms
5,376 KB
testcase_51 AC 9 ms
5,376 KB
testcase_52 AC 15 ms
5,376 KB
testcase_53 AC 44 ms
5,376 KB
testcase_54 AC 136 ms
5,632 KB
testcase_55 AC 152 ms
5,376 KB
testcase_56 AC 44 ms
5,632 KB
testcase_57 AC 615 ms
7,552 KB
testcase_58 AC 360 ms
7,680 KB
testcase_59 AC 307 ms
7,552 KB
testcase_60 AC 412 ms
7,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

typedef struct Edge {
	struct Edge *next;
	int v;
} edge;

typedef struct {
	int key, id;
} data;

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

void push(min_heap* h, data x)
{
	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(min_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;
}

int main()
{
	int i, N, M, u, w, A[100001], B[100001], C[100001];
	edge *adj[100001] = {}, e[200001], *p;
	scanf("%d %d", &N, &M);
	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]);
	}
	for (u = 1; u <= N; u++) {
		scanf("%d %d %d", &(A[u]), &(B[u]), &(C[u]));
		if (A[u] > B[u]) {
			A[u] ^= B[u];
			B[u] ^= A[u];
			A[u] ^= B[u];
		}
		if (B[u] > C[u]) {
			B[u] ^= C[u];
			C[u] ^= B[u];
			B[u] ^= C[u];
		}
		if (A[u] > B[u]) {
			A[u] ^= B[u];
			B[u] ^= A[u];
			A[u] ^= B[u];
		}
	}
	
	int l = 1, r = 1 << 29, m, x, y, z, flag[100001], in[100001];
	min_heap h;
	data d;
	while (l < r) {
		m = (l + r) / 2;
		x = 1;
		y = 1;
		z = m;
		for (u = 1; u <= N; u++) {
			flag[u] = 0;
			in[u] = 0;
		}
		h.size = 0;
		d.key = A[1] + B[1] + C[1];
		d.id = 1;
		push(&h, d);
		in[1] = 1;
		while (h.size > 0) {
			if (h.obj[1].id == N && x + y + z > h.obj[1].key) break;
			d = pop(&h);
			if (x + y + z <= d.key) {
				h.size = 0;
				break;
			}
			u = d.id;
			in[u] = 0;
			if (flag[u] == 0) {
				if (C[u] > x) {
					x = C[u];
					if (x > y) {
						x ^= y;
						y ^= x;
						x ^= y;
					}
					if (y > z) {
						y ^= z;
						z ^= y;
						y ^= z;
					}
				}
			} else if (flag[u] == 1) {
				if (B[u] > x) {
					x = B[u];
					if (x > y) {
						x ^= y;
						y ^= x;
						x ^= y;
					}
					if (y > z) {
						y ^= z;
						z ^= y;
						y ^= z;
					}
				}
			} else {
				if (A[u] > x) {
					x = A[u];
					if (x > y) {
						x ^= y;
						y ^= x;
						x ^= y;
					}
					if (y > z) {
						y ^= z;
						z ^= y;
						y ^= z;
					}
				}
			}
			flag[u]++;
			for (p = adj[u]; p != NULL; p = p->next) {
				w = p->v;
				if (flag[w] <= 2 && in[w] == 0) {
					d.key = A[w] + B[w] + C[w];
					d.id = w;
					push(&h, d);
					in[w] = 1;
				}
			}
		}
		if (h.size > 0) r = m;
		else l = m + 1;
	}
	printf("1 1 %d\n", l);
	fflush(stdout);
	return 0;
}
0