提出 #44587799


ソースコード 拡げる

N,M = gets.split.map(&:to_i)
ABCE = (1..M).map{|e|
	a,b,c = gets.split
 	next a.to_i-1,b.to_i-1,c,e
}
S = gets

Eoo = []
Eox = Hash.new{|h,x| h[x] = [] }
Exx = []
ABCE.each{|a,b,c,e|
	if S[a]==c && S[b]==c
		Eoo<<[a,b,e]
	elsif S[a]==c
		Eox[b]<<[a,b,e]
	elsif S[b]==c
		Eox[a]<<[b,a,e]
	else
		Exx<<[a,b,e]
	end
}

E = []
G = [-1]*N
F = lambda{|a|
	G[a]<0 ? a : G[a] = F[G[a]]
}
U = lambda{|a,b|
	a,b = F[a],F[b]
	next if a==b
	a,b = b,a if G[b]<G[a]
	G[a] += G[b]
	G[b] = a
	next true
}
Eoo.each{|a,b,e|
	E<<e if U[a,b]
}

V1,*Q = {}
G.each_with_index{|g,v|
	if g==-1
		V1[v] = v
	else
		Q.concat Eox[v]
	end
}
while (a,b,e = Q.pop)
	if V1[a] && U[a,b]
		E<<e
		V1.delete a
		Q.concat Eox[a]
	end
end
unless V1.empty?
	puts 'No'
#warn E*' '
	exit
end
Exx.each{|a,b,e|
	E<<e if U[a,b]
}
Eox.values.each{|abes|
	abes.each{|a,b,e|
		E<<e if U[a,b]
	}
}
puts 'Yes',E*' '

提出情報

提出日時
問題 B - Red and Blue Spanning Tree
ユーザ ds14050
言語 Ruby (ruby 3.2.2)
得点 600
コード長 937 Byte
結果 AC
実行時間 655 ms
メモリ 92468 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 600 / 600
結果
AC × 4
AC × 77
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_small_00.txt, 01_small_01.txt, 01_small_02.txt, 01_small_03.txt, 01_small_04.txt, 01_small_05.txt, 01_small_06.txt, 01_small_07.txt, 01_small_08.txt, 01_small_09.txt, 01_small_10.txt, 01_small_11.txt, 01_small_12.txt, 01_small_13.txt, 01_small_14.txt, 01_small_15.txt, 01_small_16.txt, 01_small_17.txt, 02_dense_00.txt, 02_dense_01.txt, 02_dense_02.txt, 02_dense_03.txt, 02_dense_04.txt, 02_dense_05.txt, 02_dense_06.txt, 02_dense_07.txt, 02_dense_08.txt, 02_dense_09.txt, 02_dense_10.txt, 02_dense_11.txt, 03_rnd_00.txt, 03_rnd_01.txt, 03_rnd_02.txt, 03_rnd_03.txt, 03_rnd_04.txt, 03_rnd_05.txt, 03_rnd_06.txt, 03_rnd_07.txt, 04_same_00.txt, 04_same_01.txt, 04_same_02.txt, 04_same_03.txt, 04_same_04.txt, 04_same_05.txt, 04_same_06.txt, 04_same_07.txt, 05_star_00.txt, 05_star_01.txt, 05_star_02.txt, 05_star_03.txt, 05_star_04.txt, 06_cycle_00.txt, 06_cycle_01.txt, 06_cycle_02.txt, 06_cycle_03.txt, 06_cycle_04.txt, 06_cycle_05.txt, 06_cycle_06.txt, 07_hand_00.txt, 07_hand_01.txt, 07_hand_02.txt, 07_hand_03.txt, 07_hand_04.txt, 07_hand_05.txt, 07_hand_06.txt, 07_hand_07.txt, 07_hand_08.txt, 07_hand_09.txt, 07_hand_10.txt, 07_hand_11.txt, 07_hand_12.txt, 07_hand_13.txt, 07_hand_14.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 120 ms 17048 KiB
00_sample_01.txt AC 43 ms 16980 KiB
00_sample_02.txt AC 43 ms 17180 KiB
00_sample_03.txt AC 41 ms 16964 KiB
01_small_00.txt AC 42 ms 17328 KiB
01_small_01.txt AC 42 ms 17332 KiB
01_small_02.txt AC 42 ms 17172 KiB
01_small_03.txt AC 43 ms 17220 KiB
01_small_04.txt AC 43 ms 17100 KiB
01_small_05.txt AC 43 ms 17228 KiB
01_small_06.txt AC 43 ms 17288 KiB
01_small_07.txt AC 43 ms 17228 KiB
01_small_08.txt AC 43 ms 17236 KiB
01_small_09.txt AC 43 ms 17180 KiB
01_small_10.txt AC 42 ms 17220 KiB
01_small_11.txt AC 42 ms 17104 KiB
01_small_12.txt AC 42 ms 17264 KiB
01_small_13.txt AC 42 ms 17100 KiB
01_small_14.txt AC 43 ms 17060 KiB
01_small_15.txt AC 43 ms 17120 KiB
01_small_16.txt AC 43 ms 17100 KiB
01_small_17.txt AC 42 ms 17124 KiB
02_dense_00.txt AC 195 ms 35832 KiB
02_dense_01.txt AC 249 ms 43304 KiB
02_dense_02.txt AC 208 ms 35916 KiB
02_dense_03.txt AC 227 ms 41792 KiB
02_dense_04.txt AC 208 ms 36108 KiB
02_dense_05.txt AC 324 ms 53764 KiB
02_dense_06.txt AC 181 ms 34684 KiB
02_dense_07.txt AC 123 ms 26432 KiB
02_dense_08.txt AC 179 ms 34736 KiB
02_dense_09.txt AC 143 ms 29380 KiB
02_dense_10.txt AC 135 ms 29176 KiB
02_dense_11.txt AC 171 ms 33880 KiB
03_rnd_00.txt AC 411 ms 78156 KiB
03_rnd_01.txt AC 191 ms 36292 KiB
03_rnd_02.txt AC 293 ms 59656 KiB
03_rnd_03.txt AC 512 ms 77284 KiB
03_rnd_04.txt AC 401 ms 62004 KiB
03_rnd_05.txt AC 311 ms 53144 KiB
03_rnd_06.txt AC 386 ms 57680 KiB
03_rnd_07.txt AC 434 ms 68072 KiB
04_same_00.txt AC 355 ms 64044 KiB
04_same_01.txt AC 362 ms 62688 KiB
04_same_02.txt AC 434 ms 74408 KiB
04_same_03.txt AC 286 ms 51268 KiB
04_same_04.txt AC 326 ms 65708 KiB
04_same_05.txt AC 373 ms 64792 KiB
04_same_06.txt AC 264 ms 52572 KiB
04_same_07.txt AC 325 ms 64968 KiB
05_star_00.txt AC 546 ms 86888 KiB
05_star_01.txt AC 554 ms 86324 KiB
05_star_02.txt AC 568 ms 88380 KiB
05_star_03.txt AC 585 ms 87104 KiB
05_star_04.txt AC 549 ms 87608 KiB
06_cycle_00.txt AC 547 ms 84320 KiB
06_cycle_01.txt AC 540 ms 83788 KiB
06_cycle_02.txt AC 543 ms 84200 KiB
06_cycle_03.txt AC 627 ms 92468 KiB
06_cycle_04.txt AC 655 ms 92284 KiB
06_cycle_05.txt AC 514 ms 72912 KiB
06_cycle_06.txt AC 513 ms 72948 KiB
07_hand_00.txt AC 386 ms 60736 KiB
07_hand_01.txt AC 388 ms 60412 KiB
07_hand_02.txt AC 301 ms 59632 KiB
07_hand_03.txt AC 298 ms 59860 KiB
07_hand_04.txt AC 406 ms 67856 KiB
07_hand_05.txt AC 426 ms 70920 KiB
07_hand_06.txt AC 484 ms 73728 KiB
07_hand_07.txt AC 509 ms 77792 KiB
07_hand_08.txt AC 576 ms 79604 KiB
07_hand_09.txt AC 608 ms 89956 KiB
07_hand_10.txt AC 639 ms 91572 KiB
07_hand_11.txt AC 651 ms 92088 KiB
07_hand_12.txt AC 648 ms 92044 KiB
07_hand_13.txt AC 611 ms 84332 KiB
07_hand_14.txt AC 611 ms 84364 KiB