We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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
Cookie support is required to access HackerRank
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 →
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...
where
solve
is the function that returnsTrue
is it is a valid relation andFalse
otherwise