結果

問題 No.1898 Battle and Exchange
ユーザー 👑 ygussanyygussany
提出日時 2022-03-20 10:59:30
言語 C
(gcc 12.3.0)
結果
RE  
実行時間 -
コード長 2,717 bytes
コンパイル時間 176 ms
コンパイル使用メモリ 32,768 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-16 02:36:58
合計ジャッジ時間 24,345 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 8 ms
5,376 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 AC 11 ms
5,376 KB
testcase_09 AC 23 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 62 ms
5,376 KB
testcase_12 AC 38 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 27 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 RE -
testcase_17 AC 15 ms
5,376 KB
testcase_18 AC 96 ms
5,376 KB
testcase_19 AC 201 ms
5,376 KB
testcase_20 AC 79 ms
5,376 KB
testcase_21 AC 447 ms
6,784 KB
testcase_22 AC 20 ms
5,376 KB
testcase_23 AC 5 ms
5,376 KB
testcase_24 RE -
testcase_25 RE -
testcase_26 AC 2 ms
5,376 KB
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 AC 3 ms
5,376 KB
testcase_32 AC 136 ms
5,376 KB
testcase_33 AC 383 ms
5,376 KB
testcase_34 AC 145 ms
5,376 KB
testcase_35 AC 265 ms
5,376 KB
testcase_36 AC 177 ms
5,376 KB
testcase_37 RE -
testcase_38 AC 458 ms
7,552 KB
testcase_39 AC 93 ms
6,656 KB
testcase_40 RE -
testcase_41 AC 64 ms
6,144 KB
testcase_42 AC 26 ms
5,376 KB
testcase_43 AC 173 ms
5,888 KB
testcase_44 AC 2 ms
5,376 KB
testcase_45 AC 59 ms
5,376 KB
testcase_46 AC 246 ms
5,376 KB
testcase_47 RE -
testcase_48 AC 13 ms
5,376 KB
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 RE -
testcase_56 AC 264 ms
10,112 KB
testcase_57 AC 1,078 ms
7,296 KB
testcase_58 AC 615 ms
7,296 KB
testcase_59 AC 529 ms
7,168 KB
testcase_60 AC 760 ms
7,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

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

typedef struct {
	int key, id;
} data;

typedef struct {
	data obj[600001];
	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];
	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;
		h.size = 0;
		d.key = A[1] + B[1] + C[1];
		d.id = 1;
		push(&h, d);
		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;
			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) {
					d.key = A[w] + B[w] + C[w];
					d.id = w;
					push(&h, d);
				}
			}
		}
		if (h.size > 0) r = m;
		else l = m + 1;
	}
	printf("1 1 %d\n", l);
	fflush(stdout);
	return 0;
}
0