• + 0 comments

    Reading the input can be do easily as below. By the way, despite of the fact that problem states that "You are given a set of unique ordered pairs constituting a relation", the test cases actually contain not-ordered pairs...

    main :: IO ()
    main = do  
      t <- readLn
      replicateM_ t $ do 
        n <- readLn
        l <- replicateM n $ do 
          xy <- getLine
          let [x,y] = words xy
          return (read x, read y)
        if solve l then putStrLn "YES" else putStrLn "NO"
    

    where solve is the function that returns True is it is a valid relation and False otherwise