結果

問題 No.583 鉄道同好会
ユーザー ikdikd
提出日時 2017-10-27 23:16:37
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 782 bytes
コンパイル時間 530 ms
コンパイル使用メモリ 84,704 KB
実行使用メモリ 11,040 KB
最終ジャッジ日時 2023-09-03 16:33:57
合計ジャッジ時間 1,809 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 25 ms
4,380 KB
testcase_12 AC 34 ms
4,380 KB
testcase_13 AC 34 ms
4,380 KB
testcase_14 AC 35 ms
4,376 KB
testcase_15 AC 44 ms
4,416 KB
testcase_16 AC 84 ms
11,032 KB
testcase_17 AC 101 ms
11,040 KB
testcase_18 AC 104 ms
11,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int n, m; rd(n, m);
  auto deg=new int[](n);
  auto g=new int[][](n, 0);
  foreach(_; 0..m){
    int a, b; rd(a, b);
    g[a]~=b; g[b]~=a;
    deg[a]++; deg[b]++;
  }

  auto vis=new bool[](n);
  void f(int i){
    vis[i]=true;
    foreach(j; g[i]){
      if(!vis[j]) f(j);
    }
  }

  int cnt=0;
  foreach(i; 0..n)if(!vis[i] && g[i].length>0){
    f(i); cnt++;
  }
  if(cnt>1){writeln("NO"); return;}
  auto ev=reduce!((res, e)=>res+(e%2==0))(0, deg);
  auto od=reduce!((res, e)=>res+(e&1))(0, deg);
  if(ev==n || od==2) writeln("YES");
  else writeln("NO");
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}
0