結果

問題 No.629 グラフの中に眠る門松列
ユーザー te-shte-sh
提出日時 2018-07-24 17:12:55
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 5 ms / 4,000 ms
コード長 1,062 bytes
コンパイル時間 1,106 ms
コンパイル使用メモリ 101,200 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-03 20:49:09
合計ジャッジ時間 3,541 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 4 ms
4,380 KB
testcase_25 AC 4 ms
4,376 KB
testcase_26 AC 4 ms
4,376 KB
testcase_27 AC 5 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 3 ms
4,376 KB
testcase_30 AC 4 ms
4,376 KB
testcase_31 AC 5 ms
4,380 KB
testcase_32 AC 4 ms
4,376 KB
testcase_33 AC 5 ms
4,380 KB
testcase_34 AC 3 ms
4,380 KB
testcase_35 AC 4 ms
4,376 KB
testcase_36 AC 5 ms
4,380 KB
testcase_37 AC 4 ms
4,376 KB
testcase_38 AC 4 ms
4,376 KB
testcase_39 AC 3 ms
4,376 KB
testcase_40 AC 3 ms
4,380 KB
testcase_41 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n, m; readV(n, m);
  int[] a; readA(n, a);

  auto g = Graph!int(n);
  foreach (_; 0..m) {
    int u, v; readV(u, v); --u; --v;
    g.addEdgeB(u, v);
  }

  foreach (i; 0..n) {
    auto b = a.indexed(g[i]);
    auto v1 = b.filter!(bi => bi > a[i]).array;
    auto v2 = b.filter!(bi => bi < a[i]).array;
    if (v1.sort().uniq.walkLength >= 2 || v2.sort().uniq.walkLength >= 2) {
      writeln("YES");
      return;
    }
  }

  writeln("NO");
}

struct Graph(N = int)
{
  alias Node = N;
  Node n;
  Node[][] g;
  alias g this;
  this(Node n) { this.n = n; g = new Node[][](n); }
  void addEdge(Node u, Node v) { g[u] ~= v; }
  void addEdgeB(Node u, Node v) { g[u] ~= v; g[v] ~= u; }
}
0