Submission #63566575


Source Code Expand

(N,M),*XYZ = $<.map{|ln| ln.split.map(&:to_i) }
G = [-1]*(N+1)
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
}
E = Array.new(N+1){[]}
XYZ.each{|x,y,z|
	U[x,y]
	E[x]<<[y,z]
	E[y]<<[x,z]
}
A = [nil]*(N+1)
(1..N).group_by(&F).each{|r,gs|
	A[r] = 0
	q = [r]
	while (x = q.shift)
		a = A[x]
		E[x].each{|y,z|
			z ^= a
			if A[y]
				if A[y]!=z
					p(-1)
					exit
				end
			else
				A[y] = z
				q<<y
			end
		}
	end
	a0 = (30.times.map{|b|
		n = gs.sum{|i| A[i][b] }
		m = gs.size-n
		next [n<m ? 0 : 1]
	}.reverse*'').to_i(2)
	gs.each{|i|
		A[i] ^= a0
	}
}
puts A[1,N].map{_1||0}*' '

Submission Info

Submission Time
Task E - Min of Restricted Sum
User ds14050
Language Ruby (ruby 3.2.2)
Score 450
Code Size 727 Byte
Status AC
Exec Time 2995 ms
Memory 82388 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 3
AC × 38
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 01_handmade_05.txt, 01_handmade_06.txt, 01_handmade_07.txt, 01_handmade_08.txt, 01_handmade_09.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt, 02_random_20.txt, 02_random_21.txt, 02_random_22.txt, 02_random_23.txt, 02_random_24.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 98 ms 17408 KiB
00_sample_01.txt AC 44 ms 17212 KiB
00_sample_02.txt AC 47 ms 17188 KiB
01_handmade_00.txt AC 45 ms 17244 KiB
01_handmade_01.txt AC 2967 ms 56384 KiB
01_handmade_02.txt AC 43 ms 17136 KiB
01_handmade_03.txt AC 113 ms 45824 KiB
01_handmade_04.txt AC 49 ms 17204 KiB
01_handmade_05.txt AC 114 ms 45324 KiB
01_handmade_06.txt AC 2995 ms 59964 KiB
01_handmade_07.txt AC 2093 ms 80232 KiB
01_handmade_08.txt AC 2034 ms 78480 KiB
01_handmade_09.txt AC 221 ms 33796 KiB
02_random_00.txt AC 535 ms 50676 KiB
02_random_01.txt AC 2833 ms 68660 KiB
02_random_02.txt AC 1388 ms 59432 KiB
02_random_03.txt AC 2150 ms 82252 KiB
02_random_04.txt AC 2470 ms 61180 KiB
02_random_05.txt AC 2526 ms 64864 KiB
02_random_06.txt AC 745 ms 59292 KiB
02_random_07.txt AC 2169 ms 82388 KiB
02_random_08.txt AC 1941 ms 52064 KiB
02_random_09.txt AC 2715 ms 69712 KiB
02_random_10.txt AC 213 ms 33868 KiB
02_random_11.txt AC 2694 ms 70908 KiB
02_random_12.txt AC 225 ms 36792 KiB
02_random_13.txt AC 304 ms 55400 KiB
02_random_14.txt AC 197 ms 33836 KiB
02_random_15.txt AC 487 ms 65980 KiB
02_random_16.txt AC 229 ms 39516 KiB
02_random_17.txt AC 325 ms 56752 KiB
02_random_18.txt AC 2284 ms 61640 KiB
02_random_19.txt AC 2240 ms 81092 KiB
02_random_20.txt AC 142 ms 22368 KiB
02_random_21.txt AC 547 ms 45328 KiB
02_random_22.txt AC 363 ms 34412 KiB
02_random_23.txt AC 565 ms 46992 KiB
02_random_24.txt AC 231 ms 33816 KiB