提出 #44587755


ソースコード 拡げる

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]
}
puts 'Yes',E*' '

提出情報

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

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 600
結果
AC × 4
AC × 56
WA × 21
セット名 テストケース
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 137 ms 16968 KiB
00_sample_01.txt AC 45 ms 17160 KiB
00_sample_02.txt AC 46 ms 17108 KiB
00_sample_03.txt AC 45 ms 16884 KiB
01_small_00.txt AC 44 ms 16868 KiB
01_small_01.txt AC 45 ms 17204 KiB
01_small_02.txt AC 44 ms 17028 KiB
01_small_03.txt AC 44 ms 17216 KiB
01_small_04.txt AC 45 ms 17232 KiB
01_small_05.txt AC 44 ms 17168 KiB
01_small_06.txt AC 45 ms 17236 KiB
01_small_07.txt WA 44 ms 17148 KiB
01_small_08.txt WA 44 ms 17236 KiB
01_small_09.txt AC 44 ms 16968 KiB
01_small_10.txt AC 44 ms 17144 KiB
01_small_11.txt AC 44 ms 17160 KiB
01_small_12.txt AC 44 ms 17212 KiB
01_small_13.txt AC 45 ms 17204 KiB
01_small_14.txt AC 43 ms 17172 KiB
01_small_15.txt AC 44 ms 16788 KiB
01_small_16.txt AC 47 ms 17172 KiB
01_small_17.txt AC 47 ms 17204 KiB
02_dense_00.txt WA 218 ms 35780 KiB
02_dense_01.txt WA 287 ms 43188 KiB
02_dense_02.txt WA 248 ms 36380 KiB
02_dense_03.txt WA 266 ms 41580 KiB
02_dense_04.txt WA 239 ms 35892 KiB
02_dense_05.txt WA 380 ms 53524 KiB
02_dense_06.txt WA 201 ms 35020 KiB
02_dense_07.txt WA 138 ms 26328 KiB
02_dense_08.txt WA 205 ms 35100 KiB
02_dense_09.txt WA 156 ms 29548 KiB
02_dense_10.txt WA 147 ms 29216 KiB
02_dense_11.txt WA 191 ms 33740 KiB
03_rnd_00.txt AC 545 ms 77056 KiB
03_rnd_01.txt AC 226 ms 36620 KiB
03_rnd_02.txt AC 334 ms 58780 KiB
03_rnd_03.txt WA 533 ms 76816 KiB
03_rnd_04.txt WA 424 ms 61820 KiB
03_rnd_05.txt WA 333 ms 52952 KiB
03_rnd_06.txt AC 406 ms 59040 KiB
03_rnd_07.txt WA 480 ms 67620 KiB
04_same_00.txt AC 421 ms 63020 KiB
04_same_01.txt AC 436 ms 62532 KiB
04_same_02.txt AC 519 ms 72924 KiB
04_same_03.txt AC 338 ms 51080 KiB
04_same_04.txt AC 405 ms 65712 KiB
04_same_05.txt AC 462 ms 64448 KiB
04_same_06.txt AC 320 ms 52796 KiB
04_same_07.txt AC 365 ms 64956 KiB
05_star_00.txt AC 632 ms 85744 KiB
05_star_01.txt AC 615 ms 85068 KiB
05_star_02.txt AC 618 ms 85524 KiB
05_star_03.txt AC 647 ms 85844 KiB
05_star_04.txt AC 606 ms 85828 KiB
06_cycle_00.txt WA 671 ms 78852 KiB
06_cycle_01.txt WA 682 ms 78620 KiB
06_cycle_02.txt WA 670 ms 78560 KiB
06_cycle_03.txt AC 810 ms 92016 KiB
06_cycle_04.txt AC 814 ms 92296 KiB
06_cycle_05.txt AC 647 ms 72080 KiB
06_cycle_06.txt AC 568 ms 72800 KiB
07_hand_00.txt AC 428 ms 60096 KiB
07_hand_01.txt AC 440 ms 59764 KiB
07_hand_02.txt AC 340 ms 59576 KiB
07_hand_03.txt AC 343 ms 60040 KiB
07_hand_04.txt AC 490 ms 68460 KiB
07_hand_05.txt AC 554 ms 71064 KiB
07_hand_06.txt AC 598 ms 73280 KiB
07_hand_07.txt AC 637 ms 76296 KiB
07_hand_08.txt AC 739 ms 78376 KiB
07_hand_09.txt AC 757 ms 88672 KiB
07_hand_10.txt AC 723 ms 91388 KiB
07_hand_11.txt AC 717 ms 91804 KiB
07_hand_12.txt AC 738 ms 91856 KiB
07_hand_13.txt AC 693 ms 83472 KiB
07_hand_14.txt AC 751 ms 83084 KiB