結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
15,192 KB
testcase_01 AC 80 ms
15,112 KB
testcase_02 AC 78 ms
15,204 KB
testcase_03 AC 78 ms
15,132 KB
testcase_04 AC 79 ms
15,160 KB
testcase_05 AC 181 ms
21,276 KB
testcase_06 AC 220 ms
20,084 KB
testcase_07 AC 249 ms
20,412 KB
testcase_08 AC 151 ms
19,096 KB
testcase_09 AC 151 ms
19,492 KB
testcase_10 AC 227 ms
22,660 KB
testcase_11 AC 217 ms
22,200 KB
testcase_12 AC 276 ms
26,132 KB
testcase_13 AC 177 ms
20,604 KB
testcase_14 AC 130 ms
17,732 KB
testcase_15 AC 189 ms
22,380 KB
testcase_16 AC 183 ms
21,052 KB
testcase_17 AC 182 ms
21,232 KB
testcase_18 AC 185 ms
21,416 KB
testcase_19 AC 220 ms
23,520 KB
testcase_20 AC 156 ms
18,976 KB
testcase_21 AC 121 ms
17,292 KB
testcase_22 AC 206 ms
22,112 KB
testcase_23 AC 206 ms
25,732 KB
testcase_24 AC 232 ms
25,048 KB
testcase_25 AC 189 ms
23,292 KB
testcase_26 AC 384 ms
24,420 KB
testcase_27 WA -
testcase_28 AC 151 ms
21,500 KB
testcase_29 AC 153 ms
21,396 KB
testcase_30 AC 79 ms
15,348 KB
testcase_31 AC 78 ms
15,148 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 = if M == 0
      []
    else
      A.zip(B)
    end
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