Building adjacency matrix in C++ with heaps and priority queues.