Prim's algorithm for finding the minimum spanning tree
#n is the number of nodes m is the number of edges
n, m = [int(x) for x in raw_input().split(" ")]  



well, instead of writing this comment it would be much better to give your variables meaningful and descriptive names, In this way you won't have to read the comment and the variables to know what they are about.  

The same applies to g, pq, a.........etc.etc