結果

問題 No.408 五輪ピック
ユーザー wotsushiwotsushi
提出日時 2017-02-18 11:54:25
言語 Ruby
(3.3.0)
結果
AC  
実行時間 253 ms / 5,000 ms
コード長 568 bytes
コンパイル時間 302 ms
コンパイル使用メモリ 11,568 KB
実行使用メモリ 25,892 KB
最終ジャッジ日時 2023-08-28 18:47:57
合計ジャッジ時間 7,136 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
15,064 KB
testcase_01 AC 84 ms
15,268 KB
testcase_02 AC 84 ms
15,356 KB
testcase_03 AC 87 ms
15,128 KB
testcase_04 AC 84 ms
15,364 KB
testcase_05 AC 193 ms
21,584 KB
testcase_06 AC 157 ms
18,576 KB
testcase_07 AC 182 ms
20,040 KB
testcase_08 AC 161 ms
19,156 KB
testcase_09 AC 161 ms
19,368 KB
testcase_10 AC 148 ms
18,928 KB
testcase_11 AC 145 ms
18,452 KB
testcase_12 AC 189 ms
21,060 KB
testcase_13 AC 188 ms
20,876 KB
testcase_14 AC 105 ms
16,396 KB
testcase_15 AC 204 ms
22,676 KB
testcase_16 AC 195 ms
21,032 KB
testcase_17 AC 192 ms
21,116 KB
testcase_18 AC 196 ms
21,416 KB
testcase_19 AC 201 ms
21,904 KB
testcase_20 AC 123 ms
17,080 KB
testcase_21 AC 105 ms
16,144 KB
testcase_22 AC 147 ms
19,096 KB
testcase_23 AC 224 ms
25,892 KB
testcase_24 AC 253 ms
24,900 KB
testcase_25 AC 204 ms
23,324 KB
testcase_26 AC 218 ms
22,760 KB
testcase_27 AC 215 ms
22,904 KB
testcase_28 AC 162 ms
20,696 KB
testcase_29 AC 164 ms
20,612 KB
testcase_30 AC 86 ms
15,048 KB
testcase_31 AC 86 ms
15,172 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 (not d2[a].empty?) and (not d2[b].empty?) and
           (d2[a] | d2[b] | Set[a, b]).size >= 4}
        "YES"
      else
        "NO"
      end
puts ans
0