// File: /workspace/github_cpp_makefile_star2_O2/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 $0x2778, %rsp           # imm = 0x2778
movq %rdi, %r14
leaq 0x38(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x62a2
movq 0x28(%rbx), %rax
movq %rax, 0x18(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x61d8
movq %r14, 0x28(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x2250
movl %eax, %esi
leaq 0x13f0(%rsp), %rdi
callq 0x64be
leaq 0x40(%rsp), %r15
leaq 0x38(%rsp), %r12
leaq 0x10(%rsp), %r13
cmpq $0x3, 0x18(%rsp)
jb 0x578c
movabsq $0xc800000001, %rax     # imm = 0xC800000001
movq %rax, 0x30(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x13f0(%rsp), %rsi
callq 0x622e
movl %eax, 0x10(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x5114
testq %rax, %rax
je 0x55ce
movq %r12, %rdi
movq %r13, %rsi
callq 0x512e
movq 0x8(%rax), %rcx
subq (%rax), %rcx
shrq $0x2, %rcx
decl %ecx
andl $0x0, 0x20(%rsp)
movl %ecx, 0x24(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x13f0(%rsp), %rsi
callq 0x622e
movl %eax, %ebx
movq %r12, %rdi
movq %r13, %rsi
callq 0x512e
movslq %ebx, %rsi
movq %rax, %rdi
callq 0x6236
movl (%rax), %eax
movl %eax, 0xc(%rsp)
movq %r12, %rdi
leaq 0xc(%rsp), %rsi
callq 0x5114
testq %rax, %rax
je 0x55ce
movl 0x10(%rsp), %eax
cmpl 0xc(%rsp), %eax
je 0x55ce
movq %r12, %rdi
leaq 0xc(%rsp), %rsi
callq 0x512e
movq (%rax), %rbx
movq 0x8(%rax), %r14
cmpq %r14, %rbx
je 0x56c1
movl (%rbx), %eax
movl %eax, 0x14(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x512e
movq %rax, %rdi
leaq 0x14(%rsp), %rsi
callq 0x4ffc
addq $0x4, %rbx
jmp 0x5698
movq 0x50(%rsp), %r14
cmpq %r15, %r14
je 0x5704
leaq 0x20(%r14), %rsi
movq %r12, %rdi
callq 0x512e
movq (%rax), %rcx
movq 0x8(%rax), %rax
cmpq %rax, %rcx
je 0x56f7
movl (%rcx), %edx
cmpl 0xc(%rsp), %edx
jne 0x56f1
movl 0x10(%rsp), %edx
movl %edx, (%rcx)
addq $0x4, %rcx
jmp 0x56de
movq %r14, %rdi
callq 0x2170
movq %rax, %r14
jmp 0x56c6
movq %r12, %rdi
leaq 0xc(%rsp), %rsi
callq 0x6756
decq 0x18(%rsp)
xorl %r14d, %r14d
leaq (,%r14,4), %rbp
movq %r12, %rdi
movq %r13, %rsi
callq 0x512e
movq 0x8(%rax), %rcx
subq (%rax), %rcx
sarq $0x2, %rcx
cmpq %rcx, %r14
jae 0x55ce
movq %r12, %rdi
movq %r13, %rsi
callq 0x512e
movq %rax, %rdi
movq %r14, %rsi
callq 0x6236
movl (%rax), %eax
cmpl 0x10(%rsp), %eax
jne 0x5787
movq %r12, %rdi
movq %r13, %rsi
callq 0x512e
movq %rax, %rbx
movq %r12, %rdi
movq %r13, %rsi
callq 0x512e
movq (%rax), %rsi
addq %rbp, %rsi
movq %rbx, %rdi
callq 0x6258
jmp 0x5721
incq %r14
jmp 0x5719
pushq $-0x1
popq %r14
pushq $-0x1
popq %rbx
movq 0x50(%rsp), %rax
movq %r14, %r12
cmpq %r15, %rax
je 0x57cc
cmpl $-0x1, %ebx
je 0x57b3
movq 0x30(%rax), %r12
subq 0x28(%rax), %r12
sarq $0x2, %r12
jmp 0x57c2
movl 0x20(%rax), %ebx
movq 0x30(%rax), %r14
subq 0x28(%rax), %r14
sarq $0x2, %r14
movq %rax, %rdi
callq 0x2170
jmp 0x579b
cmpq %r12, %r14
jne 0x580d
movq 0x28(%rsp), %rax
movq 0x30(%rax), %rbx
cmpq %rbx, %r14
cmovbq %r14, %rbx
movq %rbx, 0x30(%rax)
leaq 0x68(%rsp), %rdi
callq 0x6292
leaq 0x38(%rsp), %rdi
callq 0x586e
movl %ebx, %eax
addq $0x2778, %rsp           # imm = 0x2778
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3f8b(%rip), %rdi      # 0x979f
leaq 0x3f93(%rip), %rsi      # 0x97ae
leaq 0x3f9e(%rip), %rcx      # 0x97c0
movl $0xa4, %edx
callq 0x2150
movq %rax, %rbx
jmp 0x5850
jmp 0x5843
jmp 0x5843
jmp 0x5843
jmp 0x5843
jmp 0x5843
jmp 0x5843
jmp 0x5843
jmp 0x5843
jmp 0x5843
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x6292
leaq 0x38(%rsp), %rdi
callq 0x586e
movq %rbx, %rdi
callq 0x22f0