結果

問題 No.1254 補強への架け橋
ユーザー pengin_2000pengin_2000
提出日時 2020-10-09 23:06:32
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 2,051 bytes
コンパイル時間 865 ms
コンパイル使用メモリ 31,100 KB
実行使用メモリ 5,676 KB
最終ジャッジ日時 2023-09-27 19:29:32
合計ジャッジ時間 9,891 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,380 KB
testcase_01 AC 0 ms
4,380 KB
testcase_02 AC 0 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 0 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 0 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 0 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 0 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 0 ms
4,376 KB
testcase_13 AC 0 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 0 ms
4,380 KB
testcase_17 AC 0 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 0 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 0 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 0 ms
4,376 KB
testcase_27 AC 0 ms
4,376 KB
testcase_28 AC 0 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 0 ms
4,380 KB
testcase_32 AC 0 ms
4,380 KB
testcase_33 AC 0 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 0 ms
4,380 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 1 ms
4,376 KB
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 1 ms
4,376 KB
testcase_46 AC 1 ms
4,380 KB
testcase_47 AC 1 ms
4,376 KB
testcase_48 AC 1 ms
4,380 KB
testcase_49 AC 1 ms
4,376 KB
testcase_50 AC 1 ms
4,376 KB
testcase_51 AC 1 ms
4,380 KB
testcase_52 AC 1 ms
4,376 KB
testcase_53 AC 1 ms
4,376 KB
testcase_54 AC 1 ms
4,376 KB
testcase_55 AC 1 ms
4,376 KB
testcase_56 AC 1 ms
4,380 KB
testcase_57 AC 1 ms
4,380 KB
testcase_58 AC 1 ms
4,376 KB
testcase_59 AC 1 ms
4,376 KB
testcase_60 AC 0 ms
4,376 KB
testcase_61 AC 1 ms
4,380 KB
testcase_62 AC 1 ms
4,380 KB
testcase_63 AC 6 ms
4,380 KB
testcase_64 AC 2 ms
4,380 KB
testcase_65 AC 4 ms
4,380 KB
testcase_66 AC 4 ms
4,380 KB
testcase_67 AC 2 ms
4,376 KB
testcase_68 AC 3 ms
4,380 KB
testcase_69 AC 5 ms
4,376 KB
testcase_70 AC 2 ms
4,376 KB
testcase_71 AC 2 ms
4,376 KB
testcase_72 AC 4 ms
4,376 KB
testcase_73 AC 2 ms
4,380 KB
testcase_74 AC 4 ms
4,376 KB
testcase_75 AC 3 ms
4,376 KB
testcase_76 AC 1 ms
4,380 KB
testcase_77 AC 3 ms
4,376 KB
testcase_78 AC 6 ms
4,376 KB
testcase_79 AC 6 ms
4,380 KB
testcase_80 AC 5 ms
4,376 KB
testcase_81 AC 6 ms
4,376 KB
testcase_82 AC 6 ms
4,376 KB
testcase_83 AC 80 ms
5,488 KB
testcase_84 AC 76 ms
5,460 KB
testcase_85 AC 43 ms
4,376 KB
testcase_86 AC 63 ms
4,988 KB
testcase_87 AC 72 ms
5,296 KB
testcase_88 AC 8 ms
4,380 KB
testcase_89 AC 80 ms
5,516 KB
testcase_90 AC 47 ms
4,376 KB
testcase_91 AC 36 ms
4,380 KB
testcase_92 AC 17 ms
4,376 KB
testcase_93 AC 61 ms
4,668 KB
testcase_94 AC 54 ms
4,456 KB
testcase_95 AC 52 ms
4,548 KB
testcase_96 AC 73 ms
5,256 KB
testcase_97 AC 34 ms
4,384 KB
testcase_98 AC 74 ms
5,416 KB
testcase_99 AC 42 ms
4,380 KB
testcase_100 AC 84 ms
5,576 KB
testcase_101 AC 16 ms
4,376 KB
testcase_102 AC 8 ms
4,376 KB
testcase_103 AC 17 ms
4,376 KB
testcase_104 AC 25 ms
4,380 KB
testcase_105 AC 60 ms
4,780 KB
testcase_106 AC 32 ms
4,376 KB
testcase_107 AC 77 ms
5,496 KB
testcase_108 AC 78 ms
5,336 KB
testcase_109 AC 59 ms
4,684 KB
testcase_110 AC 53 ms
4,568 KB
testcase_111 AC 56 ms
4,724 KB
testcase_112 AC 23 ms
4,380 KB
testcase_113 AC 50 ms
4,488 KB
testcase_114 AC 31 ms
4,376 KB
testcase_115 AC 10 ms
4,376 KB
testcase_116 AC 36 ms
4,376 KB
testcase_117 AC 23 ms
4,380 KB
testcase_118 AC 72 ms
5,344 KB
testcase_119 AC 41 ms
4,376 KB
testcase_120 AC 70 ms
5,236 KB
testcase_121 AC 18 ms
4,376 KB
testcase_122 AC 36 ms
4,380 KB
testcase_123 AC 0 ms
4,376 KB
testcase_124 AC 67 ms
5,624 KB
testcase_125 AC 63 ms
5,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
int a[200005], b[200005];
int h[200005], l;
int comp_h(int x, int y)
{
	if (a[h[x]] > a[h[y]])
		return 1;
	else
		return -1;
}
void swap_h(int x, int y)
{
	int f = h[x];
	h[x] = h[y];
	h[y] = f;
	return;
}
void push(int ne)
{
	h[l] = ne;
	int p = l;
	l++;
	for (; p > 0; p = (p - 1) / 2)
		if (comp_h((p - 1) / 2, p) > 0)
			swap_h((p - 1) / 2, p);
	return;
}
int pop()
{
	l--;
	swap_h(0, l);
	int p = 0;
	for (;;)
	{
		if (2 * p + 2 < l)
		{
			if (comp_h(2 * p + 1, 2 * p + 2) > 0)
			{
				if (comp_h(p, 2 * p + 2) > 0)
					swap_h(p, 2 * p + 2);
				p = 2 * p + 2;
			}
			else
			{
				if (comp_h(p, 2 * p + 1) > 0)
					swap_h(p, 2 * p + 1);
				p = 2 * p + 1;
			}
		}
		else if (2 * p + 1 < l)
		{
			if (comp_h(p, 2 * p + 1) > 0)
				swap_h(p, 2 * p + 1);
			p = 2 * p + 1;
		}
		else
			break;
	}
	return h[l];
}
int main()
{
	int n;
	scanf("%d", &n);
	int i;
	for (i = 0; i < n; i++)
	{
		i *= 2;
		scanf("%d %d", &a[i], &b[i]);
		a[i]--;
		b[i]--;
		a[i + 1] = b[i];
		b[i + 1] = a[i];
		i /= 2;
	}
	l = 0;
	for (i = 0; i < 2 * n; i++)
		push(i);
	int c[200005];
	for (i = 0; i < 2 * n; i++)
		c[i] = pop();
	int cnt[100005];
	for (i = 0; i < n; i++)
		cnt[i] = 0;
	for (i = 0; i < n; i++)
	{
		i *= 2;
		cnt[a[i]]++;
		cnt[b[i]]++;
		i /= 2;
	}
	int u[100005];
	for (i = 0; i < n; i++)
		u[i] = 0;
	l = 0;
	for (i = 0; i < n; i++)
	{
		if (cnt[i] == 1)
		{
			h[l] = i;
			l++;
		}
	}
	int min, mid, max;
	c[2 * n] = 2 * n;
	a[2 * n] = -1;
	while (l > 0)
	{
		l--;
		i = h[l];
		min = -1;
		max = 2 * n;
		while (max - min > 1)
		{
			mid = (max + min) / 2;
			if (a[c[mid]] < i)
				min = mid;
			else
				max = mid;
		}
		while (a[c[max]] == i)
		{
			cnt[b[c[max]]]--;
			u[c[max] / 2] = 1;
			if (cnt[b[c[max]]] == 1)
			{
				h[l] = b[c[max]];
				l++;
			}
			max++;
		}
	}
	int k = 0;
	for (i = 0; i < n; i++)
		if (u[i] == 0)
			k++;
	printf("%d\n", k);
	for (i = 0; i < n; i++)
	{
		if (u[i] == 0)
		{
			printf("%d", i + 1);
			k--;
			if (k > 0)
				printf(" ");
			else
				printf("\n");
		}
	}
	return 0;
}
0