// File: 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:
subq $0x138, %rsp            # imm = 0x138
movq %rdi, 0x130(%rsp)
movq $0x0, 0x128(%rsp)
movl $0x1, 0xfc(%rsp)
leaq 0xfc(%rsp), %rax
movq %rax, 0x100(%rsp)
movq $0x1, 0x108(%rsp)
leaq 0xfb(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x101e0
movq 0x28(%rsp), %rcx
movq 0x100(%rsp), %rsi
movq 0x108(%rsp), %rdx
leaq 0x110(%rsp), %rdi
callq 0x101f0
jmp 0x3f78
leaq 0xfb(%rsp), %rdi
callq 0x10280
leaq 0xd0(%rsp), %rdi
callq 0x10290
leaq 0x110(%rsp), %rdi
callq 0x102a0
movq %rax, 0x20(%rsp)
movq 0x130(%rsp), %rdi
callq 0x102c0
movq %rax, %rcx
movq 0x20(%rsp), %rax
cmpq %rcx, %rax
je 0x4253
leaq 0xc4(%rsp), %rdi
callq 0x102d0
movl $0x98967f, 0xc0(%rsp) # imm = 0x98967F
leaq 0x110(%rsp), %rax
movq %rax, 0xb8(%rsp)
movq 0xb8(%rsp), %rdi
callq 0x102f0
movq %rax, 0xb0(%rsp)
movq 0xb8(%rsp), %rdi
callq 0x10320
movq %rax, 0xa8(%rsp)
leaq 0xb0(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x10350
testb $0x1, %al
jne 0x4032
jmp 0x4218
leaq 0xb0(%rsp), %rdi
callq 0x10390
movl (%rax), %eax
movl %eax, 0xa4(%rsp)
movq 0x130(%rsp), %rdi
leaq 0xa4(%rsp), %rsi
callq 0x103a0
movq %rax, 0x18(%rsp)
jmp 0x4064
movq 0x18(%rsp), %rax
movq %rax, 0x98(%rsp)
movq 0x98(%rsp), %rdi
callq 0x10490
movq %rax, 0x90(%rsp)
movq 0x98(%rsp), %rdi
callq 0x104c0
movq %rax, 0x88(%rsp)
leaq 0x90(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x104f0
testb $0x1, %al
jne 0x40b9
jmp 0x4204
leaq 0x90(%rsp), %rdi
callq 0x10530
movl 0x8(%rax), %ecx
movl %ecx, 0x80(%rsp)
movq (%rax), %rax
movq %rax, 0x78(%rsp)
leaq 0x110(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x102f0
movq 0x8(%rsp), %rdi
movq %rax, 0x68(%rsp)
callq 0x10320
movq %rax, 0x60(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x105e0
movq %rax, %rdx
movq 0x68(%rsp), %rdi
movq 0x60(%rsp), %rsi
callq 0x10580
movq %rax, 0x10(%rsp)
jmp 0x4121
movq 0x10(%rsp), %rax
movq %rax, 0x70(%rsp)
leaq 0x110(%rsp), %rdi
callq 0x10320
movq %rax, 0x58(%rsp)
leaq 0x70(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x10540
testb $0x1, %al
jne 0x4155
jmp 0x41f0
leaq 0x78(%rsp), %rdi
callq 0x105f0
movl (%rax), %eax
cmpl 0xc0(%rsp), %eax
jge 0x41ee
leaq 0xc4(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x10600
leaq 0x78(%rsp), %rdi
callq 0x105f0
movl (%rax), %eax
movl %eax, 0xc0(%rsp)
jmp 0x41ee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf0(%rsp)
movl %eax, 0xec(%rsp)
leaq 0xfb(%rsp), %rdi
callq 0x10280
jmp 0x4307
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf0(%rsp)
movl %eax, 0xec(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0x10760
leaq 0x110(%rsp), %rdi
callq 0x107c0
jmp 0x4307
jmp 0x41f0
jmp 0x41f2
leaq 0x90(%rsp), %rdi
callq 0x10640
jmp 0x409b
jmp 0x4206
leaq 0xb0(%rsp), %rdi
callq 0x10660
jmp 0x4014
leaq 0xd0(%rsp), %rdi
leaq 0xc4(%rsp), %rsi
callq 0x10680
jmp 0x422f
leaq 0xc4(%rsp), %rdi
callq 0x105e0
movq %rax, %rsi
leaq 0x110(%rsp), %rdi
callq 0x106f0
jmp 0x424e
jmp 0x3f92
leaq 0xd0(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rdi
callq 0x10490
movq %rax, 0x48(%rsp)
movq 0x50(%rsp), %rdi
callq 0x104c0
movq %rax, 0x40(%rsp)
leaq 0x48(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x104f0
testb $0x1, %al
jne 0x4293
jmp 0x42d5
leaq 0x48(%rsp), %rdi
callq 0x10530
movq (%rax), %rcx
movq %rcx, 0x34(%rsp)
movl 0x8(%rax), %eax
movl %eax, 0x3c(%rsp)
leaq 0x34(%rsp), %rdi
callq 0x105f0
movslq (%rax), %rax
addq 0x128(%rsp), %rax
movq %rax, 0x128(%rsp)
leaq 0x48(%rsp), %rdi
callq 0x10640
jmp 0x427e
movq 0x128(%rsp), %rax
movq %rax, (%rsp)
leaq 0xd0(%rsp), %rdi
callq 0x10760
leaq 0x110(%rsp), %rdi
callq 0x107c0
movq (%rsp), %rax
addq $0x138, %rsp            # imm = 0x138
retq
movq 0xf0(%rsp), %rdi
callq 0x3460
nopw %cs:(%rax,%rax)