結果

問題 No.583 鉄道同好会
ユーザー ikdikd
提出日時 2017-10-27 23:16:37
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 782 bytes
コンパイル時間 648 ms
コンパイル使用メモリ 100,320 KB
実行使用メモリ 10,568 KB
最終ジャッジ日時 2024-06-12 22:12:39
合計ジャッジ時間 1,789 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

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