// File: /workspace/github_cpp_makefile_star2_O1/Manca[P]algorithms1/./assignment3.hpp
// Function: assignment3::Graph::mincut()
int mincut()
        {
            std::map<int, std::vector<int>> contractedList = adjacencyList; // make a copy of starting list
            size_t n = contractedList.size();
            
            // random generator
            std::random_device rd;
            std::mt19937 gen(rd());
            
            while (n > 2)
            {
                // random vertex from the list of vertices (we know that there are 200 of them,
                // but the correct way should be random vertex from min key to max key
                std::uniform_int_distribution<int> vertexDistribution(1, 200);
                int u = vertexDistribution(gen);

                // if randomly selected u has already been deleted from the list, let's skip it
                if (contractedList.count(u) == 0)
                    continue;
                
                // random edge selection for the given first vertex
                size_t uSize = contractedList[u].size();
                std::uniform_int_distribution<int > edgeDistribution(0, (int)(uSize - 1)); // [a,b]
                int e = edgeDistribution(gen);
                
                // find a node in adjacency list for given vertex represented by e
                int v = contractedList[u].at(e);
                // let's see if the node actually exists in the list
                if (contractedList.count(v) == 0 || u == v)
                    continue;
                
                // merge two nodes into one (we'll use u here and copy all the neighbors of v to u's its adjancency list)
                for (int node : contractedList[v])
                    contractedList[u].push_back(node);
                
                // point other vertices that were pointing to v to u
                for (const auto& map_el : contractedList)
                    for (int& neighbor : contractedList[map_el.first])  // we'll mutate neighbor here
                        if (neighbor == v)
                            neighbor = u;
                
         
                // erase the adjacency list of v and decrease number of nodes by one
                contractedList.erase(v);
                n--;
                
                // finally, let's clean all self loops in a merged node
                size_t i = 0;
                while (i < contractedList[u].size())
                    if (contractedList[u].at(i) == u)
                        contractedList[u].erase(begin(contractedList[u]) + i);
                    else i++;
            }
            
            // last two nodes and their sizes (corresponding to number of crossing edges)
            int u = -1, v = -1;
            size_t uSize = -1, vSize = -1;
            for (const auto& map_el : contractedList)
            {
                if (u == -1)
                {
                    u = map_el.first;
                    uSize = map_el.second.size();
                }
                else
                {
                    v = map_el.first;
                    vSize = map_el.second.size();
                }
            }
            
            // uSize must be the same as vSize
            assert(uSize == vSize);
            
            size_t currentMinCut = uSize;   // either uSize or vSize
            _minCut =  currentMinCut < _minCut ? currentMinCut : _minCut;
            
            return (int)_minCut;
        }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2768, %rsp           # imm = 0x2768
movq %rdi, %r14
leaq 0x28(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x753c
movq 0x28(%rbx), %rbx
leaq 0x13e0(%rsp), %rdi
callq 0x74d2
leaq 0x13e0(%rsp), %rdi
callq 0x2260
movq %r14, 0x18(%rsp)
movl %eax, %eax
movq %rax, 0x58(%rsp)
movl $0x1, %ecx
movq %rax, %rdx
shrq $0x1e, %rdx
xorl %eax, %edx
imull $0x6c078965, %edx, %eax # imm = 0x6C078965
addl %ecx, %eax
movq %rax, 0x58(%rsp,%rcx,8)
incq %rcx
cmpq $0x270, %rcx            # imm = 0x270
jne 0x68a9
movq $0x270, 0x13d8(%rsp) # imm = 0x270
leaq 0x30(%rsp), %r15
cmpq $0x3, %rbx
jb 0x6b5d
leaq 0x28(%rsp), %r12
leaq 0x4(%rsp), %r13
movabsq $0xc800000001, %rax     # imm = 0xC800000001
movq %rax, 0x20(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x58(%rsp), %rsi
movq %rdi, %rdx
callq 0x7742
movl %eax, 0x4(%rsp)
movq 0x38(%rsp), %rdx
movq %r15, %rcx
testq %rdx, %rdx
je 0x693c
movq %r15, %rcx
xorl %esi, %esi
cmpl %eax, 0x20(%rdx)
setl %sil
cmovgeq %rdx, %rcx
movq 0x10(%rdx,%rsi,8), %rdx
testq %rdx, %rdx
jne 0x6925
movq %r15, %rdx
cmpq %r15, %rcx
je 0x694e
cmpl 0x20(%rcx), %eax
cmovlq %r15, %rcx
movq %rcx, %rdx
cmpq %r15, %rdx
je 0x6b53
movq %r12, %rdi
movq %r13, %rsi
callq 0x6240
movq 0x8(%rax), %rcx
subq (%rax), %rcx
shrq $0x2, %rcx
decl %ecx
movl $0x0, 0x10(%rsp)
movl %ecx, 0x14(%rsp)
leaq 0x10(%rsp), %rdi
leaq 0x58(%rsp), %rsi
movq %rdi, %rdx
callq 0x7742
movl %eax, %ebp
movq %r12, %rdi
movq %r13, %rsi
callq 0x6240
movslq %ebp, %rsi
movq (%rax), %rcx
movq 0x8(%rax), %rdx
subq %rcx, %rdx
sarq $0x2, %rdx
cmpq %rsi, %rdx
jbe 0x6c0e
movl (%rcx,%rsi,4), %eax
movl %eax, 0x8(%rsp)
movq 0x38(%rsp), %rdx
movq %r15, %rcx
testq %rdx, %rdx
je 0x69e2
movq %r15, %rcx
xorl %esi, %esi
cmpl %eax, 0x20(%rdx)
setl %sil
cmovgeq %rdx, %rcx
movq 0x10(%rdx,%rsi,8), %rdx
testq %rdx, %rdx
jne 0x69cb
movq %r15, %rdx
cmpq %r15, %rcx
je 0x69f4
cmpl 0x20(%rcx), %eax
cmovlq %r15, %rcx
movq %rcx, %rdx
cmpq %r15, %rdx
je 0x6b53
cmpl %eax, 0x4(%rsp)
je 0x6b53
movq %r12, %rdi
leaq 0x8(%rsp), %rsi
callq 0x6240
movq (%rax), %r14
movq 0x8(%rax), %rbp
cmpq %rbp, %r14
je 0x6a5f
movl (%r14), %eax
movl %eax, 0xc(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x6240
movq 0x8(%rax), %rsi
cmpq 0x10(%rax), %rsi
je 0x6a4c
movl 0xc(%rsp), %ecx
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rax)
jmp 0x6a59
movq %rax, %rdi
leaq 0xc(%rsp), %rdx
callq 0x739e
addq $0x4, %r14
jmp 0x6a1b
movq 0x40(%rsp), %rbp
cmpq %r15, %rbp
je 0x6aa5
leaq 0x20(%rbp), %rsi
movq %r12, %rdi
callq 0x6240
movq (%rax), %rcx
movq 0x8(%rax), %rax
cmpq %rax, %rcx
je 0x6a95
movl (%rcx), %edx
cmpl 0x8(%rsp), %edx
jne 0x6a8f
movl 0x4(%rsp), %edx
movl %edx, (%rcx)
addq $0x4, %rcx
jmp 0x6a7c
movq %rbp, %rdi
callq 0x2150
movq %rax, %rbp
cmpq %r15, %rax
jne 0x6a69
movq %r12, %rdi
leaq 0x8(%rsp), %rsi
callq 0x799c
movq %r12, %rdi
movq %rax, %rsi
callq 0x7a14
decq %rbx
xorl %ebp, %ebp
movq %r12, %rdi
movq %r13, %rsi
callq 0x6240
movq 0x8(%rax), %rcx
subq (%rax), %rcx
sarq $0x2, %rcx
cmpq %rcx, %rbp
jae 0x6b53
movq %r12, %rdi
movq %r13, %rsi
callq 0x6240
movq (%rax), %rcx
movq 0x8(%rax), %rdx
subq %rcx, %rdx
sarq $0x2, %rdx
cmpq %rbp, %rdx
jbe 0x6bfd
movl (%rcx,%rbp,4), %eax
cmpl 0x4(%rsp), %eax
jne 0x6b4b
movq %r12, %rdi
movq %r13, %rsi
callq 0x6240
movq %rax, %r14
movq %r12, %rdi
movq %r13, %rsi
callq 0x6240
movq (%rax), %rax
leaq (%rax,%rbp,4), %rsi
addq $0x4, %rsi
movq 0x8(%r14), %rdx
cmpq %rdx, %rsi
je 0x6b41
leaq (%rax,%rbp,4), %rdi
subq %rsi, %rdx
callq 0x22c0
addq $-0x4, 0x8(%r14)
jmp 0x6ac2
incq %rbp
jmp 0x6ac2
cmpq $0x2, %rbx
ja 0x68f0
movq 0x40(%rsp), %rax
cmpq %r15, %rax
je 0x6bab
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq $-0x1, %rbx
movq $-0x1, %r14
cmpl $-0x1, %ebp
je 0x6b8d
movq 0x30(%rax), %rbx
subq 0x28(%rax), %rbx
sarq $0x2, %rbx
jmp 0x6b9c
movl 0x20(%rax), %ebp
movq 0x30(%rax), %r14
subq 0x28(%rax), %r14
sarq $0x2, %r14
movq %rax, %rdi
callq 0x2150
cmpq %r15, %rax
jne 0x6b7a
jmp 0x6bb9
movq $-0x1, %r14
movq $-0x1, %rbx
cmpq %rbx, %r14
jne 0x6c1c
movq 0x18(%rsp), %rax
movq 0x30(%rax), %rbx
cmpq %rbx, %r14
cmovbq %r14, %rbx
movq %rbx, 0x30(%rax)
leaq 0x13e0(%rsp), %rdi
callq 0x21a0
leaq 0x28(%rsp), %rdi
callq 0x6c8e
movl %ebx, %eax
addq $0x2768, %rsp           # imm = 0x2768
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3c45(%rip), %rdi      # 0xa849
movq %rbp, %rsi
xorl %eax, %eax
callq 0x2290
leaq 0x3c34(%rip), %rdi      # 0xa849
xorl %eax, %eax
callq 0x2290
leaq 0x3bdc(%rip), %rdi      # 0xa7ff
leaq 0x3be4(%rip), %rsi      # 0xa80e
leaq 0x3bef(%rip), %rcx      # 0xa820
movl $0xa4, %edx
callq 0x2120
jmp 0x6c7a
jmp 0x6c58
movq %rax, %rbx
jmp 0x6c68
jmp 0x6c58
jmp 0x6c58
jmp 0x6c58
jmp 0x6c58
jmp 0x6c58
jmp 0x6c58
jmp 0x6c58
jmp 0x6c58
jmp 0x6c58
jmp 0x6c58
movq %rax, %rbx
leaq 0x13e0(%rsp), %rdi
callq 0x21a0
leaq 0x28(%rsp), %rdi
callq 0x6c8e
movq %rbx, %rdi
callq 0x2310
movq %rax, %rdi
callq 0x6c82