// File: /workspace/github_cpp_makefile_star2_O1/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, 0x10(%rsp)
movq %rdi, 0x18(%rsp)
callq 0x88b8
movq %rax, %r12
leaq 0x50(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x8d16(%rip), %rsi      # 0xe813
leaq 0x8d28(%rip), %rdx      # 0xe82c
leaq 0x40(%rsp), %rdi
callq 0xbb3a
leaq 0x40(%rsp), %rsi
movq %r12, %rdi
callq 0x8904
movq 0x40(%rsp), %rdi
cmpq %r14, %rdi
je 0x5b2a
callq 0x2200
movq %rbx, 0x60(%rsp)
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movl $0x2, %esi
callq 0x8fba
movq 0x10(%rsp), %rax
leal 0x1(%rax), %r14d
movslq %r14d, %r12
leaq (,%r14,8), %rax
leaq (%rax,%rax,2), %rbx
xorl %r13d, %r13d
leaq (,%r13,2), %r15
addq %r13, %r15
leaq (,%r15,8), %rdi
addq 0x20(%rsp), %rdi
movq %r12, %rsi
callq 0x9036
cmpl $0x0, 0x10(%rsp)
js 0x5bad
xorl %ebp, %ebp
movq 0x20(%rsp), %rax
movq (%rax,%r15,8), %rdi
addq %rbp, %rdi
movq %r12, %rsi
callq 0x90b8
addq $0x18, %rbp
cmpq %rbp, %rbx
jne 0x5b90
leaq 0x1(%r13), %rax
testq %r13, %r13
movq %rax, %r13
je 0x5b67
cmpl $0x0, 0x10(%rsp)
jle 0x5c23
movl $0x1, %r12d
xorl %ebx, %ebx
leaq 0x40(%rsp), %r13
leaq (%r12,%r12,2), %r15
movl $0x1, %ebp
leaq (%rbx,%rbp), %rax
xorl %ecx, %ecx
cmpq $0x1, %rax
je 0x5c01
movl %r12d, %edi
movl %ebp, %esi
movq 0x18(%rsp), %rdx
movq %r13, %rcx
callq 0x5a48
movl $0x3ffffffe, %ecx       # imm = 0x3FFFFFFE
testb %al, %al
je 0x5c01
movl 0x40(%rsp), %ecx
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq (%rax,%r15,8), %rax
movl %ecx, (%rax,%rbp,4)
incq %rbp
cmpq %rbp, %r14
jne 0x5bd6
incq %r12
decq %rbx
cmpq %r14, %r12
jne 0x5bcd
callq 0x88b8
movq %rax, %rdi
callq 0x894e
callq 0x88b8
movq %rax, %r15
leaq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %r12
movq %r12, (%rdi)
leaq 0x8be1(%rip), %rsi      # 0xe82d
leaq 0x8bf2(%rip), %rdx      # 0xe845
callq 0xbb3a
leaq 0x40(%rsp), %rsi
movq %r15, %rdi
callq 0x8904
movq 0x40(%rsp), %rdi
cmpq %r12, %rdi
je 0x5c74
callq 0x2200
movq 0x10(%rsp), %rax
movl %eax, %r15d
testl %eax, %eax
setle %bl
jle 0x5dd1
movl $0x1, %ebp
movb %bl, 0xf(%rsp)
movq 0x20(%rsp), %rcx
movq (%rcx), %rax
movq 0x18(%rcx), %rcx
leaq (,%rbp,2), %rdx
addq %rbp, %rdx
movq (%rax,%rdx,8), %rdx
xorl %ebx, %ebx
movl $0x1, %r12d
leaq (,%r12,8), %rsi
leaq (%rsi,%rsi,2), %rdi
movq (%rax,%rdi), %rsi
movq (%rcx,%rdi), %rdi
movl $0x1, %r8d
movl (%rdx,%r8,4), %r9d
addl (%rsi,%rbp,4), %r9d
movl (%rsi,%r8,4), %r10d
cmpl %r10d, %r9d
cmovgel %r10d, %r9d
movl %r9d, (%rdi,%r8,4)
movl %r9d, (%rsi,%r8,4)
incq %r8
cmpq %r8, %r14
jne 0x5ccd
leaq (%r12,%r12,2), %r13
movq (%rcx,%r13,8), %rsi
cmpl $0x0, (%rsi,%r12,4)
js 0x5d17
cmpq %r15, %r12
leaq 0x1(%r12), %rsi
setae %bl
movq %rsi, %r12
cmpq %r14, %rsi
jne 0x5cb3
jmp 0x5db0
movl $0x19, %edx
movq 0xf2b5(%rip), %rdi      # 0x14fd8
leaq 0x8b1c(%rip), %rsi      # 0xe846
callq 0x2250
movq 0xf2a2(%rip), %rdi      # 0x14fd8
movl %r12d, %esi
callq 0x2350
movl $0x10, %edx
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rdi
leaq 0x8b0c(%rip), %rsi      # 0xe860
callq 0x2250
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rax
movq 0x18(%rax), %rax
movq (%rax,%r13,8), %rax
movl (%rax,%r12,4), %esi
callq 0x2350
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2210
movsbl %al, %esi
movq %r12, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2190
callq 0x88b8
movq %rax, %rdi
callq 0x894e
testb $0x1, %bl
je 0x5dc8
cmpq %r15, %rbp
leaq 0x1(%rbp), %rax
setae %bl
movq %rax, %rbp
cmpq %r14, %rax
jne 0x5c8c
jmp 0x5dd1
movb 0xf(%rsp), %bl
testb $0x1, %bl
je 0x5e34
callq 0x88b8
movq %rax, %rdi
callq 0x894e
cmpl $0x0, 0x10(%rsp)
movq 0x60(%rsp), %r11
jle 0x5e34
movl (%r11), %ecx
movq 0x20(%rsp), %rax
leaq 0x1(%r15), %rdx
movl $0x1, %esi
xorl %edi, %edi
leaq (%rsi,%rsi,2), %r8
xorl %r9d, %r9d
cmpq %r9, %rdi
je 0x5e21
movq 0x18(%rax), %r10
movq (%r10,%r8,8), %r10
movl 0x4(%r10,%r9,4), %r10d
cmpl %ecx, %r10d
jge 0x5e21
movl %r10d, (%r11)
movl %r10d, %ecx
incq %r9
cmpq %r9, %r15
jne 0x5e04
incq %rsi
incq %rdi
cmpq %rdx, %rsi
jne 0x5dfd
leaq 0x20(%rsp), %rdi
callq 0x90ea
andb $0x1, %bl
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r12, %rdi
je 0x5e8c
callq 0x2200
jmp 0x5e8c
jmp 0x5e89
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r14, %rdi
je 0x5e96
callq 0x2200
jmp 0x5e96
movq %rax, %rbx
jmp 0x5e96
jmp 0x5e89
jmp 0x5e89
jmp 0x5e89
jmp 0x5e89
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x90ea
movq %rbx, %rdi
callq 0x2360