結果

問題 No.408 五輪ピック
ユーザー te-shte-sh
提出日時 2017-10-25 14:01:41
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 222 ms / 5,000 ms
コード長 950 bytes
コンパイル時間 833 ms
コンパイル使用メモリ 97,940 KB
実行使用メモリ 5,892 KB
最終ジャッジ日時 2023-09-03 16:26:24
合計ジャッジ時間 2,760 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 20 ms
4,432 KB
testcase_06 AC 11 ms
4,376 KB
testcase_07 AC 16 ms
4,376 KB
testcase_08 AC 13 ms
4,384 KB
testcase_09 AC 13 ms
4,380 KB
testcase_10 AC 12 ms
4,380 KB
testcase_11 AC 11 ms
4,380 KB
testcase_12 AC 19 ms
5,892 KB
testcase_13 AC 19 ms
4,376 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 26 ms
4,956 KB
testcase_16 AC 19 ms
4,380 KB
testcase_17 AC 18 ms
4,384 KB
testcase_18 AC 18 ms
5,404 KB
testcase_19 AC 20 ms
4,380 KB
testcase_20 AC 6 ms
4,376 KB
testcase_21 AC 4 ms
4,380 KB
testcase_22 AC 10 ms
4,380 KB
testcase_23 AC 36 ms
5,200 KB
testcase_24 AC 31 ms
4,376 KB
testcase_25 AC 40 ms
4,900 KB
testcase_26 AC 23 ms
4,384 KB
testcase_27 AC 55 ms
5,444 KB
testcase_28 AC 75 ms
4,380 KB
testcase_29 AC 222 ms
4,384 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto rd1 = readln.split.to!(size_t[]), n = rd1[0], m = rd1[1];

  struct Edge
  {
    int a, b;
    auto rev() { return Edge(b, a); }
  }

  auto e = new Edge[](m);
  foreach (i; 0..m) {
    auto rd2 = readln.splitter;
    auto a = rd2.front.to!int-1; rd2.popFront();
    auto b = rd2.front.to!int-1;
    e[i] = a < b ? Edge(a, b) : Edge(b, a);
  }

  auto u1 = new bool[](n);
  foreach (ei; e)
    if (ei.a == 0) u1[ei.b] = true;

  Edge[] f;

  foreach (ei; e)
    if (ei.a != 0) {
      if (u1[ei.a]) f ~= ei;
      if (u1[ei.b]) f ~= ei.rev;
    }

  auto fs = f.sort!"a.b < b.b";

  foreach (ei; e) {
    auto v1 = fs.equalRange(ei);
    auto v2 = fs.equalRange(ei.rev);

    foreach (v1i; v1)
      foreach (v2i; v2)
        if (v1i.a != v2i.a && v1i.a != v2i.b && v1i.b != v2i.a) {
          writeln("YES");
          return;
        }
  }

  writeln("NO");
}
0