// File: xukmin[P]rase/sensor-network.cc
// Function: CalculateMinimumCommunicationRange(std::vector<Position, std::allocator<Position>> const&)
double CalculateMinimumCommunicationRange(
    const std::vector<Position>& positions) {
  if (positions.size() <= 1) {
    return 0.0;
  }

  // Matrix of distances between sensors.
  std::vector<std::vector<double> > distances;
  CalculateDistances(positions, &distances);

  double min_range = 0.0;

  std::set<int> connected;
  connected.insert(0);

  std::set<int> unconnected;
  for (int i = 1; i < positions.size(); i++) {
    unconnected.insert(i);
  }

  for (int i = 1; i < positions.size(); i++) {
    int nearest = -1;
    double min_distance = DBL_MAX;
    for (std::set<int>::const_iterator c = connected.begin();
         c != connected.end(); ++c) {
      for (std::set<int>::const_iterator u = unconnected.begin();
           u != unconnected.end(); ++u) {
        if (distances[*c][*u] < min_distance) {
          min_distance = distances[*c][*u];
          nearest = *u;
        }
      }
    }
    assert(nearest > 0);
    unconnected.erase(nearest);
    connected.insert(nearest);
    min_range = std::max(min_range, min_distance);
  }

  return min_range;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x180, %rsp            # imm = 0x180
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x67a0
cmpq $0x1, %rax
ja 0x7d6b
xorps %xmm0, %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x8139
leaq -0x28(%rbp), %rdi
movq %rdi, -0x118(%rbp)
callq 0x4290
movq -0x118(%rbp), %rsi
movq -0x10(%rbp), %rdi
callq 0x7520
jmp 0x7d8d
movq $0x0, -0x40(%rbp)
leaq -0x70(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0x82c0
movq -0x130(%rbp), %rdi
movl $0x0, -0x74(%rbp)
leaq -0x74(%rbp), %rsi
callq 0x8b30
movb %dl, -0x121(%rbp)
movq %rax, -0x120(%rbp)
jmp 0x7dcb
movb -0x121(%rbp), %al
movq -0x120(%rbp), %rcx
movq %rcx, -0x88(%rbp)
movb %al, -0x80(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x82c0
movl $0x1, -0xbc(%rbp)
movslq -0xbc(%rbp), %rax
movq %rax, -0x138(%rbp)
movq -0x10(%rbp), %rdi
callq 0x67a0
movq %rax, %rcx
movq -0x138(%rbp), %rax
cmpq %rcx, %rax
jae 0x7eae
leaq -0xb8(%rbp), %rdi
leaq -0xbc(%rbp), %rsi
callq 0x8370
movb %dl, -0x141(%rbp)
movq %rax, -0x140(%rbp)
jmp 0x7e44
movb -0x141(%rbp), %al
movq -0x140(%rbp), %rcx
movq %rcx, -0xd0(%rbp)
movb %al, -0xc8(%rbp)
movl -0xbc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xbc(%rbp)
jmp 0x7df8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x812e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x8125
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x4ea0
jmp 0x8125
movl $0x1, -0xd4(%rbp)
movslq -0xd4(%rbp), %rax
movq %rax, -0x150(%rbp)
movq -0x10(%rbp), %rdi
callq 0x67a0
movq %rax, %rcx
movq -0x150(%rbp), %rax
cmpq %rcx, %rax
jae 0x80fb
movl $0xffffffff, -0xd8(%rbp) # imm = 0xFFFFFFFF
movsd 0xc2f4(%rip), %xmm0     # 0x141e8
movsd %xmm0, -0xe0(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x8480
movq %rax, -0xe8(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x84b0
movq %rax, -0xf0(%rbp)
leaq -0xe8(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x8930
testb $0x1, %al
jne 0x7f38
jmp 0x8046
leaq -0xb8(%rbp), %rdi
callq 0x8480
movq %rax, -0xf8(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x84b0
movq %rax, -0x100(%rbp)
leaq -0xf8(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x8930
testb $0x1, %al
jne 0x7f7a
jmp 0x8033
leaq -0xe8(%rbp), %rdi
callq 0x89c0
movslq (%rax), %rsi
leaq -0x28(%rbp), %rdi
callq 0x8b80
movq %rax, -0x158(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x89c0
movq -0x158(%rbp), %rdi
movslq (%rax), %rsi
callq 0x8ba0
movsd (%rax), %xmm1
movsd -0xe0(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x8020
leaq -0xe8(%rbp), %rdi
callq 0x89c0
movslq (%rax), %rsi
leaq -0x28(%rbp), %rdi
callq 0x8b80
movq %rax, -0x160(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x89c0
movq -0x160(%rbp), %rdi
movslq (%rax), %rsi
callq 0x8ba0
movsd (%rax), %xmm0
movsd %xmm0, -0xe0(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x89c0
movl (%rax), %eax
movl %eax, -0xd8(%rbp)
jmp 0x8022
leaq -0xf8(%rbp), %rdi
callq 0x8a90
jmp 0x7f4b
jmp 0x8035
leaq -0xe8(%rbp), %rdi
callq 0x8a90
jmp 0x7f0c
cmpl $0x0, -0xd8(%rbp)
jle 0x8051
jmp 0x8070
leaq 0xc359(%rip), %rdi      # 0x143b1
leaq 0xc1a4(%rip), %rsi      # 0x14203
movl $0xfd, %edx
leaq 0xc352(%rip), %rcx      # 0x143bd
callq 0x3130
leaq -0xb8(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x8bc0
jmp 0x8085
leaq -0x70(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x8370
movb %dl, -0x169(%rbp)
movq %rax, -0x168(%rbp)
jmp 0x80a4
movb -0x169(%rbp), %al
movq -0x168(%rbp), %rcx
movq %rcx, -0x110(%rbp)
movb %al, -0x108(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x8bf0
movq %rax, -0x178(%rbp)
jmp 0x80d7
movq -0x178(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
movl -0xd4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd4(%rbp)
jmp 0x7eb8
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x4ea0
leaq -0x70(%rbp), %rdi
callq 0x4ea0
leaq -0x28(%rbp), %rdi
callq 0x4520
jmp 0x8139
leaq -0x70(%rbp), %rdi
callq 0x4ea0
leaq -0x28(%rbp), %rdi
callq 0x4520
jmp 0x8147
movsd -0x8(%rbp), %xmm0
addq $0x180, %rsp            # imm = 0x180
popq %rbp
retq
movq -0x30(%rbp), %rdi
callq 0x3340