Created
June 28, 2020 03:56
-
-
Save kei-q/a37f524cf502023c21d0c62911920333 to your computer and use it in GitHub Desktop.
https://atcoder.jp/contests/abc126/tasks/abc126_d でL25-28のうちひとつだけTLEになる
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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