結果

問題 No.408 五輪ピック
ユーザー wotsushiwotsushi
提出日時 2017-02-18 11:21:58
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 620 bytes
コンパイル時間 352 ms
コンパイル使用メモリ 11,244 KB
実行使用メモリ 21,144 KB
最終ジャッジ日時 2023-08-28 18:44:51
合計ジャッジ時間 7,425 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
15,076 KB
testcase_01 AC 79 ms
15,124 KB
testcase_02 AC 78 ms
15,208 KB
testcase_03 AC 77 ms
15,292 KB
testcase_04 AC 78 ms
15,064 KB
testcase_05 AC 177 ms
20,884 KB
testcase_06 AC 124 ms
17,692 KB
testcase_07 AC 151 ms
19,312 KB
testcase_08 AC 148 ms
18,868 KB
testcase_09 AC 145 ms
18,804 KB
testcase_10 AC 129 ms
17,920 KB
testcase_11 AC 128 ms
17,696 KB
testcase_12 AC 167 ms
20,100 KB
testcase_13 AC 176 ms
20,644 KB
testcase_14 AC 97 ms
16,084 KB
testcase_15 AC 182 ms
20,896 KB
testcase_16 AC 180 ms
20,900 KB
testcase_17 AC 180 ms
21,096 KB
testcase_18 AC 181 ms
21,004 KB
testcase_19 AC 181 ms
21,124 KB
testcase_20 AC 103 ms
16,288 KB
testcase_21 AC 90 ms
15,624 KB
testcase_22 AC 123 ms
17,548 KB
testcase_23 AC 186 ms
21,144 KB
testcase_24 WA -
testcase_25 AC 182 ms
20,812 KB
testcase_26 AC 185 ms
20,964 KB
testcase_27 AC 188 ms
20,928 KB
testcase_28 AC 141 ms
18,400 KB
testcase_29 AC 143 ms
18,312 KB
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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, -1)
e.each {|a, b|
  if d1[a]
    d2[b] = if d2[b] == -1
              a
            else
              0
            end
  end
  if d1[b]
    d2[a] = if d2[a] == -1
              b
            else
              0
            end
  end
}
ans = if e.any? {|a, b| d2[a] >= 0 and d2[b] >= 0 and (d2[a] == 0 or d2[b] == 0 or (d2[a] != d2[b]))}
        "YES"
      else
        "NO"
      end
puts ans
0