// File: /workspace/github_cpp_makefile_star2_O2/Manca[P]algorithms2/./assignment4.hpp
// Function: assignment4::floyd_warshall(std::unordered_map<int, std::vector<std::pair<int, int>, std::allocator<std::pair<int, int>>>, std::hash<int>, std::equal_to<int>, std::allocator<std::pair<int const, std::vector<std::pair<int, int>, std::allocator<std::pair<int, int>>>>>>&, int, int&)
bool floyd_warshall(Graph& graph, int n, int& shortest)
    {
        PROFILE("Initialize Floyd-Warshall")
        std::vector<std::vector<std::vector<int>>> A;       // a 3D array
        // setup sizes (we will store only kth and k-1th result)
        A.resize(2);
        for (int i = 0; i < 2; i++)
        {
            A[i].resize(n+1);
            for (int j = 0; j <= n; j++)
                A[i][j].resize(n+1);
        }
        
        for (int i = 1; i <= n; i++)             // i,j are vertices (from 1 to 1000)
            for (int j = 1; j <= n; j++)
            {
                int cost;
                if (i == j)   A[0][i][j] = 0;
                else if (ijConnected(i, j, graph, cost)) A[0][i][j] = cost;
                else if (i != j)  A[0][i][j] = INT32_MAX/2 -1;
            }

        PROFILE_STOP();

        // the algorithm
        PROFILE("Floyd-Warshall algorithm");
        for (int k = 1; k <= n; k++)
        {
            for (int i = 1; i <= n; i++)
            {
                for (int j = 1; j <= n; j++)
                {
                    A[1][i][j] = std::min(A[0][i][j], A[0][i][k] + A[0][k][j]);
                    A[0][i][j] = A[1][i][j];    // store currently computed value at zero position (previous - interchange)
                }

                // check for negative cycles (if current i-th iteration reveals cycle, abort!)
                if (A[1][i][i] < 0)
                {
                    std::cout << "Negative cycle!! Vertex: " << i << ". Total weight: " << A[1][i][i] << std::endl;
                    PROFILE_STOP();
                    return false;
                }
            }
           
        }
        PROFILE_STOP();

        // find the shortest shortest path
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= n; j++)
            {
                if (i == j) continue;
                if (A[1][i][j] < shortest) shortest = A[1][i][j];
            }
        }

        return true;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdx, %rbx
movq %rsi, 0x8(%rsp)
movq %rdi, 0x60(%rsp)
callq 0x725c
movq %rax, %r12
leaq 0x88b1(%rip), %rsi      # 0xd7c3
leaq 0x38(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x2120
leaq 0x38(%rsp), %rsi
movq %r12, %rdi
callq 0x72a6
leaq 0x38(%rsp), %rdi
callq 0x2150
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rdi
movaps %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
pushq $0x2
popq %rsi
callq 0x7874
movq %rbx, 0x58(%rsp)
movq 0x8(%rsp), %rax
leal 0x1(%rax), %ebp
movslq %ebp, %r12
cltq
movq %rax, 0x30(%rsp)
xorl %ebx, %ebx
cmpq $0x2, %rbx
je 0x4fb2
imulq $0x18, %rbx, %r14
movq 0x10(%rsp), %rdi
addq %r14, %rdi
movq %r12, %rsi
callq 0x78aa
xorl %r15d, %r15d
xorl %r13d, %r13d
cmpq 0x30(%rsp), %r13
jg 0x4fad
movq 0x10(%rsp), %rax
movq (%rax,%r14), %rdi
addq %r15, %rdi
movq %r12, %rsi
callq 0x78e0
incq %r13
addq $0x18, %r15
jmp 0x4f89
incq %rbx
jmp 0x4f69
xorl %ebx, %ebx
movq 0x8(%rsp), %rax
testl %eax, %eax
cmovlel %ebx, %eax
incl %eax
movq %rax, 0x8(%rsp)
movl %ebp, %r14d
pushq $0x1
popq %r13
leaq 0x38(%rsp), %r12
cmpq 0x8(%rsp), %r13
je 0x5031
imulq $0x18, %r13, %r15
pushq $0x1
popq %rbp
cmpq %rbp, %r14
je 0x5029
leaq (%rbx,%rbp), %rdx
xorl %ecx, %ecx
movq %r13, %rax
cmpq $0x1, %rdx
je 0x5015
movl %r13d, %edi
movl %ebp, %esi
movq 0x60(%rsp), %rdx
movq %r12, %rcx
callq 0x4e81
movl $0x3ffffffe, %ecx       # imm = 0x3FFFFFFE
testb %al, %al
je 0x5012
movl 0x38(%rsp), %ecx
movq %rbp, %rax
movq 0x10(%rsp), %rdx
movq (%rdx), %rdx
movq (%rdx,%r15), %rdx
movl %ecx, (%rdx,%rax,4)
incq %rbp
jmp 0x4fdf
incq %r13
decq %rbx
jmp 0x4fd1
callq 0x725c
movq 0x58(%rsp), %r13
movq %rax, %rdi
callq 0x72c8
callq 0x725c
movq %rax, %r15
leaq 0x878b(%rip), %rsi      # 0xd7dd
leaq 0x38(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x2120
leaq 0x38(%rsp), %rsi
movq %r15, %rdi
callq 0x72a6
leaq 0x38(%rsp), %rdi
callq 0x2150
pushq $0x1
popq %rax
movq %rax, %r12
cmpq 0x8(%rsp), %r12
je 0x5175
movq 0x10(%rsp), %rcx
imulq $0x18, %r12, %rdx
movq %rax, %r15
cmpq %r14, %r15
je 0x50f2
movq 0x10(%rsp), %rsi
imulq $0x18, %r15, %rbx
movq %rax, %rdi
cmpq %rdi, %r14
je 0x50de
movq (%rsi), %r8
movq 0x18(%rsi), %r9
movq (%r8,%rbx), %r10
movq (%r8,%rdx), %r8
movl (%r8,%rdi,4), %r8d
addl (%r10,%r12,4), %r8d
movl (%r10,%rdi,4), %r11d
cmpl %r11d, %r8d
cmovgel %r11d, %r8d
movq (%r9,%rbx), %r9
movl %r8d, (%r9,%rdi,4)
movl %r8d, (%r10,%rdi,4)
incq %rdi
jmp 0x50a6
movq 0x18(%rcx), %rsi
movq (%rsi,%rbx), %rsi
cmpl $0x0, (%rsi,%r15,4)
js 0x50f7
incq %r15
jmp 0x5095
incq %r12
jmp 0x507e
movq 0x10eda(%rip), %rdi     # 0x15fd8
leaq 0x86f1(%rip), %rsi      # 0xd7f6
callq 0x2230
movq %rax, %rdi
movl %r15d, %esi
callq 0x2370
leaq 0x86f4(%rip), %rsi      # 0xd810
movq %rax, %rdi
callq 0x2230
movq 0x10(%rsp), %rcx
movq 0x18(%rcx), %rcx
movq (%rcx,%rbx), %rcx
movl (%rcx,%r15,4), %esi
movq %rax, %rdi
callq 0x2370
movq %rax, %rdi
callq 0x2160
callq 0x725c
movq %rax, %rdi
callq 0x72c8
cmpq 0x30(%rsp), %r12
setg %bl
leaq 0x10(%rsp), %rdi
callq 0x7912
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x725c
movq %rax, %rdi
callq 0x72c8
movl (%r13), %ecx
movq 0x10(%rsp), %rax
decq %r14
pushq $0x1
popq %rdx
xorl %esi, %esi
cmpq 0x8(%rsp), %rdx
je 0x5152
imulq $0x18, %rdx, %rdi
xorl %r8d, %r8d
cmpq %r8, %r14
je 0x51c9
cmpq %r8, %rsi
je 0x51c4
movq 0x18(%rax), %r9
movq (%r9,%rdi), %r9
movl 0x4(%r9,%r8,4), %r9d
cmpl %ecx, %r9d
jge 0x51c4
movl %r9d, (%r13)
movl %r9d, %ecx
incq %r8
jmp 0x51a1
incq %rdx
incq %rsi
jmp 0x5193
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x2150
jmp 0x5201
jmp 0x51fe
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x2150
jmp 0x520b
movq %rax, %rbx
jmp 0x520b
jmp 0x51fe
jmp 0x51fe
jmp 0x51fe
jmp 0x51fe
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x7912
movq %rbx, %rdi
callq 0x2380