Submission #63532221


Source Code Expand

n,m=gets.split.map(&:to_i)
g=Array.new(n+1){[]}
m.times{x,y,z=gets.split.map(&:to_i);g[x]<<[y,z];g[y]<<[x,z]}
d=Array.new(n+1)
r=Array.new(n+1,0)
(1..n).each{|i|
  next if d[i]
  q=[i];d[i]=0;comp=[]
  while !q.empty?
    u=q.shift;comp<<u
    g[u].each{|v,w|
      if d[v].nil? then d[v]=d[u]^w;q<<v
      elsif d[v]!=(d[u]^w) then puts -1;exit
      end
    }
  end
  t=0;k=comp.size
  32.times{|b| c=comp.count{|v| d[v]>>b&1==1}; t|=1<<b if k-c<c}
  comp.each{|v| r[v]=d[v]^t}
}
puts r[1..-1].join(" ")

Submission Info

Submission Time
Task E - Min of Restricted Sum
User aquix
Language Ruby (ruby 3.2.2)
Score 450
Code Size 525 Byte
Status AC
Exec Time 660 ms
Memory 50900 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 42 ms 17224 KiB
00_sample_01.txt AC 42 ms 17128 KiB
00_sample_02.txt AC 42 ms 17188 KiB
01_handmade_00.txt AC 41 ms 17372 KiB
01_handmade_01.txt AC 563 ms 36304 KiB
01_handmade_02.txt AC 41 ms 17168 KiB
01_handmade_03.txt AC 64 ms 30512 KiB
01_handmade_04.txt AC 42 ms 17160 KiB
01_handmade_05.txt AC 64 ms 30444 KiB
01_handmade_06.txt AC 562 ms 36312 KiB
01_handmade_07.txt AC 614 ms 47876 KiB
01_handmade_08.txt AC 612 ms 50900 KiB
01_handmade_09.txt AC 204 ms 29304 KiB
02_random_00.txt AC 323 ms 39104 KiB
02_random_01.txt AC 611 ms 45380 KiB
02_random_02.txt AC 546 ms 44280 KiB
02_random_03.txt AC 633 ms 50432 KiB
02_random_04.txt AC 511 ms 35448 KiB
02_random_05.txt AC 609 ms 45404 KiB
02_random_06.txt AC 397 ms 42232 KiB
02_random_07.txt AC 651 ms 50284 KiB
02_random_08.txt AC 470 ms 38380 KiB
02_random_09.txt AC 588 ms 37512 KiB
02_random_10.txt AC 178 ms 30216 KiB
02_random_11.txt AC 594 ms 37736 KiB
02_random_12.txt AC 188 ms 33088 KiB
02_random_13.txt AC 207 ms 42056 KiB
02_random_14.txt AC 136 ms 30956 KiB
02_random_15.txt AC 204 ms 40080 KiB
02_random_16.txt AC 191 ms 35188 KiB
02_random_17.txt AC 213 ms 42368 KiB
02_random_18.txt AC 496 ms 35052 KiB
02_random_19.txt AC 660 ms 49880 KiB
02_random_20.txt AC 107 ms 21536 KiB
02_random_21.txt AC 352 ms 39264 KiB
02_random_22.txt AC 241 ms 31216 KiB
02_random_23.txt AC 367 ms 40372 KiB
02_random_24.txt AC 188 ms 29880 KiB