// File: /workspace/github_cpp_makefile_star2_O2/Manca[P]algorithms2/./assignment1.hpp
// Function: assignment1::prims_algorithm::prims_algorithm(std::map<int, std::vector<std::tuple<int, int, int>, std::allocator<std::tuple<int, int, int>>>, std::less<int>, std::allocator<std::pair<int const, std::vector<std::tuple<int, int, int>, std::allocator<std::tuple<int, int, int>>>>>>&)
long long prims_algorithm(Graph& g)
        {
            long long result = 0;
            std::vector<int> X = { 1 };		// vertices spanned by tree T so far (initialize X with first vertex in first edge)
            std::vector<Edge> T;			// T is initially empty (tree_so_far)

            while (X.size() != g.size())
            {
                // let's go over all vertices in X so far and find adjancent min cost nodes
                Edge min_cost_edge;
                int min = 9999999;
                for (int u : X)	// always need to find the cheapest edge from whole set of adjacent vertices to set X
                {
                    // search min cost edge
                    for (auto edge : g[u])
                    {
                        if (std::find(X.begin(), X.end(), std::get<1>(edge)) == X.end()) // if target vertex is not in X
                        {
                            if (std::get<2>(edge) < min)
                            {
                                min_cost_edge = edge;
                                min = std::get<2>(edge);
                            }
                        }
                    }
                }
                // finally add the cheapest node overall (going out from X) and add destination node to X
                T.push_back(min_cost_edge);
                X.push_back(std::get<1>(min_cost_edge));	// add destination vertex to X
            }

            for (auto e : T)
            {
                result += std::get<2>(e);
            }

            return result;
        }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, 0x20(%rsp)
leaq 0x40(%rsp), %rbx
movl $0x1, (%rbx)
leaq 0x28(%rsp), %rdi
pushq $0x1
popq %rdx
movq %rsp, %rcx
movq %rbx, %rsi
callq 0x710e
xorps %xmm0, %xmm0
andq $0x0, 0x10(%rbx)
movaps %xmm0, (%rbx)
leaq 0x14(%rsp), %rbp
movq 0x28(%rsp), %r12
movq 0x30(%rsp), %r13
movq %r13, %rax
subq %r12, %rax
sarq $0x2, %rax
movq 0x20(%rsp), %rcx
cmpq 0x28(%rcx), %rax
je 0x2b55
andq $0x0, (%rsp)
andl $0x0, 0x8(%rsp)
movl $0x98967f, %r14d        # imm = 0x98967F
cmpq %r13, %r12
je 0x2b34
movl (%r12), %eax
movl %eax, 0xc(%rsp)
movq 0x20(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x7144
movq (%rax), %r15
movq 0x8(%rax), %rbx
cmpq %rbx, %r15
je 0x2b2e
movl 0x8(%r15), %eax
movl %eax, 0x18(%rsp)
movq (%r15), %rax
movq %rax, 0x10(%rsp)
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq %rbp, %rdx
callq 0x9fb6
cmpq 0x30(%rsp), %rax
jne 0x2b28
movl 0x10(%rsp), %eax
cmpl %r14d, %eax
jge 0x2b28
movq 0x14(%rsp), %rcx
movq %rcx, 0x4(%rsp)
movl %eax, (%rsp)
movl %eax, %r14d
addq $0xc, %r15
jmp 0x2ae1
addq $0x4, %r12
jmp 0x2abe
leaq 0x40(%rsp), %rdi
movq %rsp, %rsi
callq 0x7192
leaq 0x28(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x71b6
jmp 0x2a8b
movq 0x40(%rsp), %rax
movq 0x48(%rsp), %rcx
xorl %ebx, %ebx
cmpq %rcx, %rax
je 0x2b72
movslq (%rax), %rdx
addq %rdx, %rbx
addq $0xc, %rax
jmp 0x2b61
leaq 0x40(%rsp), %rdi
callq 0x9d3e
leaq 0x28(%rsp), %rdi
callq 0x9cda
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2b9c
jmp 0x2b9c
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x9d3e
leaq 0x28(%rsp), %rdi
callq 0x9cda
movq %rbx, %rdi
callq 0x2380