Submission #63566575
Source Code Expand
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
(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
2025-03-08 14:12:40
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 KB
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
450 / 450
Status
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 KB
00_sample_01.txt
AC
44 ms
17212 KB
00_sample_02.txt
AC
47 ms
17188 KB
01_handmade_00.txt
AC
45 ms
17244 KB
01_handmade_01.txt
AC
2967 ms
56384 KB
01_handmade_02.txt
AC
43 ms
17136 KB
01_handmade_03.txt
AC
113 ms
45824 KB
01_handmade_04.txt
AC
49 ms
17204 KB
01_handmade_05.txt
AC
114 ms
45324 KB
01_handmade_06.txt
AC
2995 ms
59964 KB
01_handmade_07.txt
AC
2093 ms
80232 KB
01_handmade_08.txt
AC
2034 ms
78480 KB
01_handmade_09.txt
AC
221 ms
33796 KB
02_random_00.txt
AC
535 ms
50676 KB
02_random_01.txt
AC
2833 ms
68660 KB
02_random_02.txt
AC
1388 ms
59432 KB
02_random_03.txt
AC
2150 ms
82252 KB
02_random_04.txt
AC
2470 ms
61180 KB
02_random_05.txt
AC
2526 ms
64864 KB
02_random_06.txt
AC
745 ms
59292 KB
02_random_07.txt
AC
2169 ms
82388 KB
02_random_08.txt
AC
1941 ms
52064 KB
02_random_09.txt
AC
2715 ms
69712 KB
02_random_10.txt
AC
213 ms
33868 KB
02_random_11.txt
AC
2694 ms
70908 KB
02_random_12.txt
AC
225 ms
36792 KB
02_random_13.txt
AC
304 ms
55400 KB
02_random_14.txt
AC
197 ms
33836 KB
02_random_15.txt
AC
487 ms
65980 KB
02_random_16.txt
AC
229 ms
39516 KB
02_random_17.txt
AC
325 ms
56752 KB
02_random_18.txt
AC
2284 ms
61640 KB
02_random_19.txt
AC
2240 ms
81092 KB
02_random_20.txt
AC
142 ms
22368 KB
02_random_21.txt
AC
547 ms
45328 KB
02_random_22.txt
AC
363 ms
34412 KB
02_random_23.txt
AC
565 ms
46992 KB
02_random_24.txt
AC
231 ms
33816 KB