We compute an MST on n2 edges: .
We then walk the tree, avoiding duplicates: O(n).
Total: (not too bad).