// File: /workspace/github_cpp_makefile_star2_O1/Kei18[P]pibt/./src/solver/cbs.cpp
// Function: CBS::solvePart(std::vector<std::vector<Node*, std::allocator<Node*>>, std::allocator<std::vector<Node*, std::allocator<Node*>>>>&, std::vector<Agent*, std::allocator<Agent*>>&)
bool CBS::solvePart(Paths& paths, Agents& block) {
  CTNode* node;
  Constraints constraints;
  std::vector<CTNode*> OPEN, ALL;
  bool status = true;

  CTNode* root = new CTNode { {}, {}, 0, nullptr, true, {}, 0 };
  invoke(root, block);
  OPEN.push_back(root);
  ALL.push_back(root);
  bool CAT = std::any_of(paths.begin(), paths.end(),
                         [](Nodes p) { return !p.empty(); });

  while (!OPEN.empty()) {
    auto itr = std::min_element(OPEN.begin(), OPEN.end(),
                                [CAT, this, &paths]
                                (CTNode* n1, CTNode* n2) {
                                  if (CAT && n1->cost == n2->cost) {
                                    int c1 = this->countCollisions(n1, paths);
                                    int c2 = this->countCollisions(n2, paths);
                                    return c1 < c2;
                                  }
                                  return n1->cost < n2->cost;
                                });
    node = *itr;
    constraints = valid(node, block);
    if (constraints.empty()) break;
    OPEN.erase(itr);

    for (auto constraint : constraints) {
      CTNode* newNode = new CTNode { constraint, node->paths,
                                     0, node, true,
                                     {}, 0 };

      // it works, but it is late
      // if (isDuplicatedCTNode(newNode, ALL)) continue;

      invoke(newNode, block);
      if (newNode->valid) {
        OPEN.push_back(newNode);
        ALL.push_back(newNode);
      }
    }
    constraints.clear();
  }

  if (!OPEN.empty()) {  // sucssess
    for (int i = 0; i < paths.size(); ++i) {
      if (!node->paths[i].empty()) {
        paths[i] = node->paths[i];
      }
    }
    status = status && true;
  } else {
    status = false;
  }

  return status;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rdx, 0x88(%rsp)
movq %rsi, %r14
movq %rdi, 0x80(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
xorl %eax, %eax
movq %rax, 0x40(%rsp)
movq %rax, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movq %rax, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movl $0x68, %edi
callq 0x6370
movq $0x0, 0x38(%rax)
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, 0x20(%rax)
movl $0x0, 0x30(%rax)
movb $0x1, 0x40(%rax)
movups %xmm0, 0x48(%rax)
movups %xmm0, 0x54(%rax)
movq %rax, 0x58(%rsp)
movq 0x80(%rsp), %rdi
movq (%rdi), %rcx
movq %rax, %rsi
movq 0x88(%rsp), %rdx
callq *0x20(%rcx)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x267d6
movq 0x58(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x18(%rsp)
jmp 0x267e5
leaq 0x10(%rsp), %rdi
leaq 0x58(%rsp), %rdx
callq 0x2b9e2
movq 0x68(%rsp), %rsi
cmpq 0x70(%rsp), %rsi
je 0x26801
movq 0x58(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x68(%rsp)
jmp 0x26810
leaq 0x60(%rsp), %rdi
leaq 0x58(%rsp), %rdx
callq 0x2b9e2
movq (%r14), %r13
movq 0x8(%r14), %rbx
movq %rbx, 0x50(%rsp)
subq %r13, %rbx
sarq $0x3, %rbx
movabsq $-0x5555555555555555, %rax # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %rbx
sarq $0x2, %rbx
testq %rbx, %rbx
jle 0x26898
incq %rbx
movq %r13, %rdi
callq 0x29ee4
testb %al, %al
jne 0x268fe
leaq 0x18(%r13), %rdi
movq %rdi, 0x8(%rsp)
callq 0x29ee4
testb %al, %al
jne 0x26903
leaq 0x30(%r13), %rdi
movq %rdi, 0x8(%rsp)
callq 0x29ee4
testb %al, %al
jne 0x26903
leaq 0x48(%r13), %rdi
movq %rdi, 0x8(%rsp)
callq 0x29ee4
testb %al, %al
jne 0x26903
addq $0x60, %r13
decq %rbx
cmpq $0x1, %rbx
jg 0x2683d
movq 0x50(%rsp), %rax
subq %r13, %rax
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rax
cmpq $0x1, %rax
je 0x268ee
cmpq $0x2, %rax
je 0x268de
movq 0x50(%rsp), %rcx
movq %rcx, 0x8(%rsp)
cmpq $0x3, %rax
jne 0x26903
movq %r13, %rdi
callq 0x29ee4
testb %al, %al
jne 0x268fe
addq $0x18, %r13
movq %r13, %rdi
callq 0x29ee4
testb %al, %al
jne 0x268fe
addq $0x18, %r13
movq %r13, %rdi
callq 0x29ee4
testb %al, %al
cmoveq 0x50(%rsp), %r13
movq %r13, 0x8(%rsp)
movq %r14, 0x78(%rsp)
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %r14
cmpq %r14, %r15
je 0x26bc4
leaq 0x8(%r15), %r13
cmpq %r14, %r13
je 0x2697e
movq (%r13), %rsi
movq (%r15), %rbx
movq 0x8(%rsp), %rax
cmpq 0x50(%rsp), %rax
je 0x2695d
movl 0x30(%rsi), %eax
cmpl 0x30(%rbx), %eax
jne 0x2695d
movq 0x78(%rsp), %r12
movq %r12, %rdx
callq 0x27638
movl %eax, %ebp
movq %rbx, %rsi
movq %r12, %rdx
callq 0x27638
cmpl %eax, %ebp
jmp 0x26963
movl 0x30(%rsi), %eax
cmpl 0x30(%rbx), %eax
setl %al
movq %r13, %rbx
testb %al, %al
jne 0x26970
movq %r15, %rbx
addq $0x8, %r13
movq %rbx, %r15
cmpq %r14, %r13
jne 0x26924
jmp 0x26981
movq %r15, %rbx
movq (%rbx), %r13
leaq 0xa8(%rsp), %r14
movq %r14, %rdi
movq 0x80(%rsp), %rsi
movq %r13, %rdx
movq 0x88(%rsp), %rcx
callq 0x26d1e
xorps %xmm0, %xmm0
movaps %xmm0, 0x90(%rsp)
movaps 0x30(%rsp), %xmm0
movq 0x40(%rsp), %rax
movups 0xa8(%rsp), %xmm1
movaps %xmm1, 0x30(%rsp)
movq 0xb8(%rsp), %rcx
movq %rcx, 0x40(%rsp)
movaps 0x90(%rsp), %xmm1
movaps %xmm0, 0x90(%rsp)
movq %rax, 0xa0(%rsp)
movups %xmm1, 0xa8(%rsp)
movq $0x0, 0xb8(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x2ab2e
movq %r14, %rdi
callq 0x2ab2e
movq 0x30(%rsp), %r12
movq 0x38(%rsp), %rax
movq %rax, 0xc0(%rsp)
cmpq %rax, %r12
je 0x26bc4
leaq 0x8(%rbx), %rsi
movq 0x18(%rsp), %rdx
cmpq %rdx, %rsi
je 0x26a4b
subq %rsi, %rdx
movq %rbx, %rdi
callq 0x65b0
addq $-0x8, 0x18(%rsp)
movq 0x30(%rsp), %rbx
movq 0x38(%rsp), %r15
cmpq %r15, %rbx
je 0x26b71
leaq 0x18(%r13), %r14
leaq 0x90(%rsp), %rdi
movq %rbx, %rsi
callq 0x2ab7c
movl $0x68, %edi
callq 0x6370
movq %rax, %rbp
movq %rax, %rdi
leaq 0x90(%rsp), %rsi
callq 0x2ab7c
movq %rbp, %rdi
addq $0x18, %rdi
movq %r14, %rsi
callq 0x2abfc
movl $0x0, 0x30(%rbp)
movq %r13, 0x38(%rbp)
movb $0x1, 0x40(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x48(%rbp)
movups %xmm0, 0x54(%rbp)
movq %rbp, 0xa8(%rsp)
movq 0x80(%rsp), %rdi
movq (%rdi), %rax
movq %rbp, %rsi
movq 0x88(%rsp), %rdx
callq *0x20(%rax)
movq 0xa8(%rsp), %rax
cmpb $0x1, 0x40(%rax)
jne 0x26b47
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x26b04
movq %rax, (%rsi)
addq $0x8, 0x18(%rsp)
jmp 0x26b16
leaq 0x10(%rsp), %rdi
leaq 0xa8(%rsp), %rdx
callq 0x2b9e2
movq 0x68(%rsp), %rsi
cmpq 0x70(%rsp), %rsi
je 0x26b35
movq 0xa8(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x68(%rsp)
jmp 0x26b47
leaq 0x60(%rsp), %rdi
leaq 0xa8(%rsp), %rdx
callq 0x2b9e2
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x26b64
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
addq $0x18, %rbx
cmpq %r15, %rbx
jne 0x26a68
movq 0x30(%rsp), %rbx
movq 0x38(%rsp), %r14
cmpq %rbx, %r14
je 0x26ba5
movq %rbx, %r15
movq (%r15), %rdi
testq %rdi, %rdi
je 0x26b97
movq 0x10(%r15), %rsi
subq %rdi, %rsi
callq 0x6380
addq $0x18, %r15
cmpq %r14, %r15
jne 0x26b83
movq %rbx, 0x38(%rsp)
cmpq 0xc0(%rsp), %r12
je 0x26bc4
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %r14
cmpq %r14, %r15
jne 0x2691b
jmp 0x26bc4
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %r14
cmpq %r14, %rbx
je 0x26c2e
movq 0x78(%rsp), %rax
movq (%rax), %rdi
cmpq %rdi, 0x8(%rax)
je 0x26c2e
xorl %r15d, %r15d
xorl %r12d, %r12d
movq 0x18(%r13), %rsi
movq (%rsi,%r15), %rax
cmpq 0x8(%rsi,%r15), %rax
je 0x26c01
addq %r15, %rsi
addq %r15, %rdi
callq 0x1b2e2
incq %r12
movq 0x78(%rsp), %rax
movq (%rax), %rdi
movq 0x8(%rax), %rax
subq %rdi, %rax
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rax
addq $0x18, %r15
cmpq %r12, %rax
ja 0x26be7
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x26c45
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x26c5c
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
cmpq %r14, %rbx
setne %bl
leaq 0x30(%rsp), %rdi
callq 0x2ab2e
movl %ebx, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x26ca6
jmp 0x26ca6
jmp 0x26ca6
jmp 0x26ca6
jmp 0x26ca6
jmp 0x26ca6
movq %rax, %rbx
movq (%rbp), %rdi
testq %rdi, %rdi
je 0x26cae
movq 0x10(%rbp), %rsi
subq %rdi, %rsi
callq 0x6380
jmp 0x26cae
movq %rax, %rbx
jmp 0x26cdd
movq %rax, %rbx
movl $0x68, %esi
movq %rbp, %rdi
callq 0x6380
jmp 0x26cc0
movq %rax, %rbx
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x26cdd
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x26cf4
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x26d0b
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x6380
leaq 0x30(%rsp), %rdi
callq 0x2ab2e
movq %rbx, %rdi
callq 0x6620
nop