結果

問題 No.408 五輪ピック
ユーザー wotsushiwotsushi
提出日時 2017-02-18 11:38:35
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 459 bytes
コンパイル時間 409 ms
コンパイル使用メモリ 11,424 KB
実行使用メモリ 26,212 KB
最終ジャッジ日時 2023-08-28 18:45:43
合計ジャッジ時間 6,883 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
15,096 KB
testcase_01 AC 79 ms
15,104 KB
testcase_02 AC 77 ms
15,332 KB
testcase_03 AC 77 ms
15,168 KB
testcase_04 AC 84 ms
15,352 KB
testcase_05 AC 181 ms
21,400 KB
testcase_06 AC 219 ms
20,088 KB
testcase_07 AC 246 ms
20,508 KB
testcase_08 AC 149 ms
19,300 KB
testcase_09 AC 150 ms
19,524 KB
testcase_10 AC 222 ms
22,544 KB
testcase_11 AC 219 ms
22,160 KB
testcase_12 AC 275 ms
26,212 KB
testcase_13 AC 178 ms
20,924 KB
testcase_14 AC 129 ms
17,812 KB
testcase_15 AC 188 ms
22,700 KB
testcase_16 AC 183 ms
21,048 KB
testcase_17 AC 182 ms
21,320 KB
testcase_18 AC 186 ms
21,568 KB
testcase_19 AC 220 ms
23,684 KB
testcase_20 AC 157 ms
18,936 KB
testcase_21 AC 121 ms
17,288 KB
testcase_22 AC 206 ms
22,128 KB
testcase_23 AC 208 ms
25,644 KB
testcase_24 AC 231 ms
24,984 KB
testcase_25 AC 187 ms
23,228 KB
testcase_26 AC 384 ms
24,480 KB
testcase_27 WA -
testcase_28 AC 153 ms
21,392 KB
testcase_29 AC 153 ms
21,368 KB
testcase_30 AC 78 ms
15,364 KB
testcase_31 AC 78 ms
15,100 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

require 'set'

N, M = gets.split.map(&:to_i)
A, B = (1..M).map {gets.split.map(&:to_i)}.transpose
e = A.zip(B)

d1 = Array.new(N + 1, false)
e.each {|a, b|
  d1[a] ||= (b == 1)
  d1[b] ||= (a == 1)
}
d2 = Array.new(N + 1) {Set.new}
e.each {|a, b|
  if d1[a]
    d2[b].add(a)
  end
  if d1[b]
    d2[a].add(b)
  end
}
ans = if e.any? {|a, b| a != 1 and b != 1 and (d2[a] | d2[b] | Set[a, b]).size >= 4}
        "YES"
      else
        "NO"
      end
puts ans
0