Submission #44572051


Source Code Expand

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 = []
Exx = []
ABCE.each{|a,b,c,e|
	if S[a]==c && S[b]==c
		Eoo<<[a,b,e]
	elsif S[a]==c
		Eox<<[a,b,e]
	elsif S[b]==c
		Eox<<[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]
}
Goo = G.count(&:negative?)
Goo1 = G.count(-1)
Eox.select{|a,|
	G[F[a]]==-1
}.each{|a,b,e|
	E<<e if U[a,b]
}
Gox = G.count(&:negative?)
if Goo-Goo1<Gox
	puts 'No'
	exit
end
Exx.each{|a,b,e|
	E<<e if U[a,b]
}
Eox.each{|a,b,e|
	E<<e if U[a,b]
}
puts 'Yes',E*' '

Submission Info

Submission Time
Task B - Red and Blue Spanning Tree
User ds14050
Language Ruby (ruby 3.2.2)
Score 0
Code Size 810 Byte
Status WA
Exec Time 667 ms
Memory 68800 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 600
Status
AC × 4
AC × 69
WA × 8
Set Name Test Cases
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
Case Name Status Exec Time Memory
00_sample_00.txt AC 132 ms 17092 KiB
00_sample_01.txt AC 43 ms 17196 KiB
00_sample_02.txt AC 44 ms 17568 KiB
00_sample_03.txt AC 43 ms 17280 KiB
01_small_00.txt AC 43 ms 17148 KiB
01_small_01.txt AC 43 ms 17296 KiB
01_small_02.txt AC 43 ms 17160 KiB
01_small_03.txt AC 43 ms 17420 KiB
01_small_04.txt AC 43 ms 17284 KiB
01_small_05.txt AC 43 ms 17296 KiB
01_small_06.txt AC 44 ms 17276 KiB
01_small_07.txt AC 43 ms 17208 KiB
01_small_08.txt AC 43 ms 17280 KiB
01_small_09.txt AC 43 ms 17192 KiB
01_small_10.txt AC 43 ms 17184 KiB
01_small_11.txt AC 43 ms 17204 KiB
01_small_12.txt AC 43 ms 17152 KiB
01_small_13.txt AC 44 ms 17148 KiB
01_small_14.txt AC 43 ms 16728 KiB
01_small_15.txt AC 43 ms 17152 KiB
01_small_16.txt AC 43 ms 17144 KiB
01_small_17.txt AC 43 ms 17308 KiB
02_dense_00.txt AC 192 ms 35340 KiB
02_dense_01.txt AC 249 ms 43568 KiB
02_dense_02.txt AC 209 ms 36028 KiB
02_dense_03.txt AC 228 ms 41132 KiB
02_dense_04.txt AC 206 ms 36268 KiB
02_dense_05.txt AC 318 ms 52480 KiB
02_dense_06.txt AC 179 ms 34544 KiB
02_dense_07.txt AC 123 ms 26176 KiB
02_dense_08.txt AC 176 ms 34644 KiB
02_dense_09.txt AC 142 ms 29720 KiB
02_dense_10.txt AC 135 ms 29416 KiB
02_dense_11.txt AC 171 ms 33748 KiB
03_rnd_00.txt AC 354 ms 57888 KiB
03_rnd_01.txt WA 196 ms 35300 KiB
03_rnd_02.txt AC 262 ms 45404 KiB
03_rnd_03.txt WA 454 ms 62392 KiB
03_rnd_04.txt WA 367 ms 54332 KiB
03_rnd_05.txt WA 277 ms 44320 KiB
03_rnd_06.txt WA 344 ms 53312 KiB
03_rnd_07.txt WA 405 ms 55732 KiB
04_same_00.txt AC 305 ms 52764 KiB
04_same_01.txt AC 351 ms 56796 KiB
04_same_02.txt AC 391 ms 61552 KiB
04_same_03.txt AC 279 ms 50456 KiB
04_same_04.txt AC 314 ms 55564 KiB
04_same_05.txt AC 349 ms 56584 KiB
04_same_06.txt AC 262 ms 47424 KiB
04_same_07.txt AC 313 ms 55576 KiB
05_star_00.txt AC 441 ms 63224 KiB
05_star_01.txt AC 449 ms 67568 KiB
05_star_02.txt AC 454 ms 67824 KiB
05_star_03.txt AC 451 ms 62412 KiB
05_star_04.txt AC 452 ms 68800 KiB
06_cycle_00.txt AC 492 ms 62084 KiB
06_cycle_01.txt AC 482 ms 61920 KiB
06_cycle_02.txt AC 489 ms 61944 KiB
06_cycle_03.txt AC 532 ms 65620 KiB
06_cycle_04.txt AC 520 ms 64992 KiB
06_cycle_05.txt WA 470 ms 64772 KiB
06_cycle_06.txt WA 471 ms 64912 KiB
07_hand_00.txt AC 333 ms 53672 KiB
07_hand_01.txt AC 332 ms 52896 KiB
07_hand_02.txt AC 289 ms 49816 KiB
07_hand_03.txt AC 293 ms 49772 KiB
07_hand_04.txt AC 351 ms 58840 KiB
07_hand_05.txt AC 356 ms 59520 KiB
07_hand_06.txt AC 440 ms 64132 KiB
07_hand_07.txt AC 448 ms 64176 KiB
07_hand_08.txt AC 478 ms 66316 KiB
07_hand_09.txt AC 517 ms 64936 KiB
07_hand_10.txt AC 518 ms 64760 KiB
07_hand_11.txt AC 667 ms 64552 KiB
07_hand_12.txt AC 667 ms 64584 KiB
07_hand_13.txt AC 540 ms 58932 KiB
07_hand_14.txt AC 539 ms 59180 KiB