092 B - Unplanned Queries

入出力

1
2
3
let N,M = stdin.ReadLine().Split() |> Array.map int |> (fun x -> x.[0],x.[1])
let Ia = Array.init M (fun _ -> stdin.ReadLine().Split() |> Array.map int |> fun x -> x.[0],x.[1])
solve N M Ia |> stdout.WriteLine

解説

公式解説通りに素直に実装します. アルゴリズムを考えるのが全てで実装は簡単です. 各頂点の出現数を数えて偶奇判定するだけのシンプルなプログラムでよいため, 次のように書けば終わりです.

1
2
3
4
5
6
7
8
9
let solve N M Ia =
  (Array.zeroCreate N, Ia)
  ||> Array.fold (fun Ga (a,b) -> Ga.[a-1]<-1+Ga.[a-1]; Ga.[b-1]<-1+Ga.[b-1]; Ga)
  |> Array.forall (fun x -> x%2=0)
  |> fun b -> if b then "YES" else "NO"

let N,M = stdin.ReadLine().Split() |> Array.map int |> (fun x -> x.[0],x.[1])
let Ia = Array.init M (fun _ -> stdin.ReadLine().Split() |> Array.map int |> fun x -> x.[0],x.[1])
solve N M Ia |> stdout.WriteLine