// File: guitld[P]Graph-Algorithms/source/Graph.cpp
// Function: Graph::minimum_tree_cost()
int Graph::minimum_tree_cost(){

     // Defining structures for the algorithm
     unordered_map<int, bool> visited;
     priority_queue <pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
     vector<int> dists (this->size(), 99999999);
     int cost = 0;

     dists[this->adj_lists.begin()->first - 1] = 0;

     pq.push(pair<int, int> (0, this->adj_lists.begin()->first));
     
     while (!pq.empty()){
          // Popping the top of the priority queue
          pair<int,int> curr_v = pq.top();
          pq.pop();
          // Check whether the node was visited or not
          if (!visited[curr_v.second]){
               // Increasing the cost
               cost += curr_v.first;
               visited[curr_v.second] = true;
               // Looping through its neighbors
               for (auto const &neighbor : this->adj_lists[curr_v.second]){
                    int v = neighbor.first;
                    int weight = neighbor.second;
                    if (!visited[neighbor.first] && dists[v - 1] > weight){
                         dists[v - 1] = weight;
                         pq.push(pair<int, int> (dists[v - 1], v));
                    }
               }
          }
     }

     return cost;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xf8(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x67d0
leaq -0x60(%rbp), %rdi
callq 0x67f0
jmp 0x54ae
movq -0xf8(%rbp), %rdi
callq 0x66f0
movl %eax, -0xfc(%rbp)
jmp 0x54c2
movl -0xfc(%rbp), %eax
cltq
movq %rax, -0x110(%rbp)
movl $0x5f5e0ff, -0x8c(%rbp) # imm = 0x5F5E0FF
leaq -0x8d(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0x6820
movq -0x110(%rbp), %rsi
movq -0x108(%rbp), %rcx
leaq -0x88(%rbp), %rdi
leaq -0x8c(%rbp), %rdx
callq 0x6840
jmp 0x5511
leaq -0x8d(%rbp), %rdi
callq 0x68c0
movq -0xf8(%rbp), %rdi
movl $0x0, -0x94(%rbp)
callq 0x5970
movq %rax, -0xa0(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x5cf0
movl (%rax), %eax
decl %eax
movslq %eax, %rsi
leaq -0x88(%rbp), %rdi
callq 0x5f70
movq -0xf8(%rbp), %rdi
movl $0x0, (%rax)
movl $0x0, -0xac(%rbp)
callq 0x5970
movq %rax, -0xb8(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x5cf0
movq %rax, %rdx
leaq -0xa8(%rbp), %rdi
leaq -0xac(%rbp), %rsi
callq 0x6a20
jmp 0x55a0
leaq -0x60(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x68e0
jmp 0x55b2
jmp 0x55b4
leaq -0x60(%rbp), %rdi
callq 0x6960
movb %al, -0x111(%rbp)
jmp 0x55c5
movb -0x111(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x55d6
jmp 0x5836
leaq -0x60(%rbp), %rdi
callq 0x6980
movq %rax, -0x120(%rbp)
jmp 0x55e8
movq -0x120(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xc0(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x69a0
jmp 0x5604
leaq -0xbc(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x69f0
movq %rax, -0x128(%rbp)
jmp 0x561d
movq -0x128(%rbp), %rax
testb $0x1, (%rax)
jne 0x5831
movl -0xc0(%rbp), %ecx
movl -0x94(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x94(%rbp)
leaq -0xbc(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x69f0
movq %rax, -0x130(%rbp)
jmp 0x565a
movq -0xf8(%rbp), %rdi
movq -0x130(%rbp), %rax
movb $0x1, (%rax)
leaq -0xbc(%rbp), %rsi
callq 0x5890
movq %rax, -0x138(%rbp)
jmp 0x5680
movq -0x138(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rdi
callq 0x5a70
movq %rax, -0xd0(%rbp)
movq -0xc8(%rbp), %rdi
callq 0x5aa0
movq %rax, -0xd8(%rbp)
leaq -0xd0(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x5ad0
testb $0x1, %al
jne 0x56d0
jmp 0x582f
leaq -0xd0(%rbp), %rdi
callq 0x5b00
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xe4(%rbp)
movq -0xe0(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0xe8(%rbp)
movq -0xe0(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x69f0
movq %rax, -0x140(%rbp)
jmp 0x571b
movq -0x140(%rbp), %rax
testb $0x1, (%rax)
jne 0x581c
movl -0xe4(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
leaq -0x88(%rbp), %rdi
callq 0x5f70
movl (%rax), %eax
cmpl -0xe8(%rbp), %eax
jle 0x581c
movl -0xe8(%rbp), %eax
movl %eax, -0x14c(%rbp)
movl -0xe4(%rbp), %eax
decl %eax
movslq %eax, %rsi
leaq -0x88(%rbp), %rdi
movq %rdi, -0x148(%rbp)
callq 0x5f70
movl -0x14c(%rbp), %ecx
movq -0x148(%rbp), %rdi
movl %ecx, (%rax)
movl -0xe4(%rbp), %eax
decl %eax
movslq %eax, %rsi
callq 0x5f70
movq %rax, %rsi
leaq -0xf0(%rbp), %rdi
leaq -0xe4(%rbp), %rdx
callq 0x5900
jmp 0x57b2
leaq -0x60(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x68e0
jmp 0x57c4
jmp 0x581c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x5878
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x586f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x8d(%rbp), %rdi
callq 0x68c0
jmp 0x586f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x5f90
jmp 0x586f
jmp 0x581e
leaq -0xd0(%rbp), %rdi
callq 0x5b20
jmp 0x56b4
jmp 0x5831
jmp 0x55b4
movl -0x94(%rbp), %eax
movl %eax, -0x150(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x5f90
leaq -0x60(%rbp), %rdi
callq 0x6a50
leaq -0x40(%rbp), %rdi
callq 0x6a70
movl -0x150(%rbp), %eax
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
leaq -0x60(%rbp), %rdi
callq 0x6a50
leaq -0x40(%rbp), %rdi
callq 0x6a70
movq -0x68(%rbp), %rdi
callq 0x22c0
nopw (%rax,%rax)