You are viewing a single comment's thread. Return to all comments →
open System let readPair() = match Console.ReadLine().Split([|' '|]) |> Array.map Int32.Parse |> Array.toList with | x::y::[] -> x, y | _ -> failwith "Invalid pair" let readPairs n = let rec readPairs n r = match n with | 0 -> r | _ -> readPairs (n - 1) (readPair()::r) readPairs n [] let rec isFunction pairs = let rec f cur rem = match cur,rem with | (x1, y1), (x2, y2)::_ when x1 = x2 && y1 <> y2 -> "NO" | _, _::ps -> f cur ps | _ -> "YES" match pairs with | [_] | [] -> "YES" | p::ps -> match f p ps with | "NO" -> "NO" | _ -> isFunction ps let runTestCase() = let n = Console.ReadLine() |> Int32.Parse let pairs = readPairs n printfn "%s" (isFunction pairs) let rec runTestCases t = match t with | 0 -> () | _ -> runTestCase() runTestCases (t - 1) let t = Console.ReadLine() |> Int32.Parse runTestCases t
Seems like cookies are disabled on this browser, please enable them to open this website
Functions or Not?
You are viewing a single comment's thread. Return to all comments →