Format of files:
First line contains value of N Second line contains value of M Next M lines contain triplets of the form node 1 node2 type