Skip to content

Instantly share code, notes, and snippets.

@kei-q
Created June 28, 2020 03:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kei-q/a37f524cf502023c21d0c62911920333 to your computer and use it in GitHub Desktop.
Save kei-q/a37f524cf502023c21d0c62911920333 to your computer and use it in GitHub Desktop.
https://atcoder.jp/contests/abc126/tasks/abc126_d でL25-28のうちひとつだけTLEになる
N,*uvws=$<.read.split.map(&:to_i)
h = {}
uvws.each_slice(3) do |u,v,w|
h[u] ||= []
h[u] << [u,v,w%2]
h[v] ||= []
h[v] << [v,u,w%2]
end
arr = Array.new(N+1,-1)
arr[1] = 0
q = h[1]
until q.empty?
u,v,w = q.shift
next if arr[v] != -1
if w == 0
arr[v] = arr[u]
else
arr[v] = 1-arr[u]
end
# Q. どれがTLE?
# q.push(*h[v])
# q.concat(h[v])
# q += h[v]
# h[v].each {|x| q << x}
end
puts arr[1..-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment