// File: sharmaeklavya2[P]ddos-on-anycast/src/lib/attack.cpp
// Function: attack(Network const&, std::vector<int, std::allocator<int>> const&, std::vector<int, std::allocator<int>>&, int, int)
void attack(const Network& network, const ivec& victims, ivec& target, int in_weight, int side_weight) {
    // TODO: Remove side edge transitivity

    normalize_edge_weights(in_weight, side_weight);
    int n = network.size();
    int h = network.height();

    // init targets
    target.resize(n, -1);
    ivec target_dist(n, -1);
    for(int v: victims) {
        target[v] = v;
        target_dist[v] = 0;
    }

    /*
    vector<ivec> depthwise_victims(h+1);
    for(int victim: victims) {
        depthwise_victims[network.depth[victim]].push_back(victim);
    }
    */

    // Apply Dijkstra's algorithm
    vector<bool> visited(n, false);
    for(int d=h; d>=0; --d) {
        // initialize targets, target_dists and heap
        PQ pq;
        for(int u: network.depthwise[d]) {
            if(target[u] == -1 && !network.down_nbrs[u].empty()) {
                ipvec dvlist;
                dvlist.reserve(network.down_nbrs[u].size());
                for(int v: network.down_nbrs[u]) {
                    if(target_dist[v] != -1) {
                        dvlist.emplace_back(target_dist[v], target[v]);
                    }
                }
                if(!dvlist.empty()) {
                    iipair min_elem = *(std::min_element(dvlist.begin(), dvlist.end()));
                    target[u] = min_elem.second;
                    target_dist[u] = 0;
                }
            }
            if(target_dist[u] != -1) {
                if(target_dist[u] != 0) {
                    fprintf(stderr, "target_dist[%d] = %d instead of 0 or -1\n", u, target_dist[u]);
                }
                pq.push(PQElem(0, u));
            }
        }

        dijkstra(network, pq, target, target_dist, visited, in_weight, side_weight);
    }

    typedef tuple<int, int, int> itrip;
    ivec target_depth(network.depth.begin(), network.depth.end());

    for(int d=1; d<=h; ++d) {
        PQ pq;
        for(int u: network.depthwise[d]) {
            if(target_dist[u] == -1 && !network.up_nbrs[u].empty()) {
                vector<itrip> dvlist;
                for(int v: network.up_nbrs[u]) {
                    if(target_dist[v] != -1) {
                        dvlist.emplace_back(-target_depth[v], target_dist[v], target[v]);
                    }
                }
                if(!dvlist.empty()) {
                    int v = std::get<2>(*(std::min_element(dvlist.begin(), dvlist.end())));
                    target[u] = target[v];
                    target_dist[u] = 0;
                    target_depth[u] = target_depth[v];
                    pq.emplace(target_dist[u], u);
                }
            }
        }

        dijkstra(network, pq, target, target_dist, visited, in_weight, side_weight);
    }
    // cerr << "target_dist: " << target_dist << endl;

    for(int i=0; i<n; ++i) {
        if(network.netsize[i] == 0 && (target[i] == -1 || target_dist[i] < 0)) {
            fprintf(stderr, "target[%d] = %d and target_dist[%d] = %d\n", i, target[i], i, target_dist[i]);
        }
    }
}

// Assembly:
subq $0x2e8, %rsp            # imm = 0x2E8
movq %rdi, 0x2e0(%rsp)
movq %rsi, 0x2d8(%rsp)
movq %rdx, 0x2d0(%rsp)
movl %ecx, 0x2cc(%rsp)
movl %r8d, 0x2c8(%rsp)
leaq 0x2cc(%rsp), %rdi
leaq 0x2c8(%rsp), %rsi
callq 0x121a0
movq 0x2e0(%rsp), %rdi
callq 0x4950
movl %eax, 0x2c4(%rsp)
movq 0x2e0(%rsp), %rdi
callq 0x4f20
movl %eax, 0x2c0(%rsp)
movq 0x2d0(%rsp), %rdi
movslq 0x2c4(%rsp), %rsi
movl $0xffffffff, 0x2bc(%rsp) # imm = 0xFFFFFFFF
leaq 0x2bc(%rsp), %rdx
callq 0x4b40
movslq 0x2c4(%rsp), %rax
movq %rax, 0xb0(%rsp)
movl $0xffffffff, 0x29c(%rsp) # imm = 0xFFFFFFFF
leaq 0x29b(%rsp), %rdi
movq %rdi, 0xb8(%rsp)
callq 0x4f40
movq 0xb0(%rsp), %rsi
movq 0xb8(%rsp), %rcx
leaq 0x2a0(%rsp), %rdi
leaq 0x29c(%rsp), %rdx
callq 0x4f50
jmp 0x128fa
leaq 0x29b(%rsp), %rdi
callq 0x4fd0
movq 0x2d8(%rsp), %rax
movq %rax, 0x280(%rsp)
movq 0x280(%rsp), %rdi
callq 0x4880
movq %rax, 0x278(%rsp)
movq 0x280(%rsp), %rdi
callq 0x48b0
movq %rax, 0x270(%rsp)
leaq 0x278(%rsp), %rdi
leaq 0x270(%rsp), %rsi
callq 0x48e0
testb $0x1, %al
jne 0x1295f
jmp 0x129f4
leaq 0x278(%rsp), %rdi
callq 0x4920
movl (%rax), %eax
movl %eax, 0x26c(%rsp)
movl 0x26c(%rsp), %eax
movl %eax, 0xac(%rsp)
movq 0x2d0(%rsp), %rdi
movslq 0x26c(%rsp), %rsi
callq 0x4860
movl 0xac(%rsp), %ecx
movl %ecx, (%rax)
movslq 0x26c(%rsp), %rsi
leaq 0x2a0(%rsp), %rdi
callq 0x4860
movl $0x0, (%rax)
leaq 0x278(%rsp), %rdi
callq 0x4930
jmp 0x12941
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x290(%rsp)
movl %eax, 0x28c(%rsp)
leaq 0x29b(%rsp), %rdi
callq 0x4fd0
jmp 0x13584
movslq 0x2c4(%rsp), %rax
movq %rax, 0x98(%rsp)
movb $0x0, 0x23f(%rsp)
leaq 0x23e(%rsp), %rdi
movq %rdi, 0xa0(%rsp)
callq 0x13840
movq 0x98(%rsp), %rsi
movq 0xa0(%rsp), %rcx
leaq 0x240(%rsp), %rdi
leaq 0x23f(%rsp), %rdx
callq 0x13850
jmp 0x12a48
leaq 0x23e(%rsp), %rdi
callq 0x138d0
movl 0x2c0(%rsp), %eax
movl %eax, 0x238(%rsp)
cmpl $0x0, 0x238(%rsp)
jl 0x12f39
leaq 0x218(%rsp), %rdi
callq 0x138e0
jmp 0x12a80
movq 0x2e0(%rsp), %rdi
addq $0xa8, %rdi
movslq 0x238(%rsp), %rsi
callq 0x4a60
movq %rax, 0x210(%rsp)
movq 0x210(%rsp), %rdi
callq 0x4880
movq %rax, 0x208(%rsp)
movq 0x210(%rsp), %rdi
callq 0x48b0
movq %rax, 0x200(%rsp)
leaq 0x208(%rsp), %rdi
leaq 0x200(%rsp), %rsi
callq 0x48e0
testb $0x1, %al
jne 0x12aec
jmp 0x12ec1
leaq 0x208(%rsp), %rdi
callq 0x4920
movl (%rax), %eax
movl %eax, 0x1fc(%rsp)
movq 0x2d0(%rsp), %rdi
movslq 0x1fc(%rsp), %rsi
callq 0x4860
cmpl $-0x1, (%rax)
jne 0x12dd4
movq 0x2e0(%rsp), %rdi
addq $0x90, %rdi
movslq 0x1fc(%rsp), %rsi
callq 0x4a60
movq %rax, %rdi
callq 0x86a0
testb $0x1, %al
jne 0x12dd4
leaq 0x1e0(%rsp), %rdi
movq %rdi, 0x90(%rsp)
callq 0x4a50
movq 0x2e0(%rsp), %rdi
addq $0x90, %rdi
movslq 0x1fc(%rsp), %rsi
callq 0x4a60
movq %rax, %rdi
callq 0x4f00
movq 0x90(%rsp), %rdi
movq %rax, %rsi
callq 0xd2d0
jmp 0x12b97
movq 0x2e0(%rsp), %rdi
addq $0x90, %rdi
movslq 0x1fc(%rsp), %rsi
callq 0x4a60
movq %rax, 0x1d8(%rsp)
movq 0x1d8(%rsp), %rdi
callq 0x4880
movq %rax, 0x1d0(%rsp)
movq 0x1d8(%rsp), %rdi
callq 0x48b0
movq %rax, 0x1c8(%rsp)
leaq 0x1d0(%rsp), %rdi
leaq 0x1c8(%rsp), %rsi
callq 0x48e0
testb $0x1, %al
jne 0x12c03
jmp 0x12cfe
leaq 0x1d0(%rsp), %rdi
callq 0x4920
movl (%rax), %eax
movl %eax, 0x1c4(%rsp)
movslq 0x1c4(%rsp), %rsi
leaq 0x2a0(%rsp), %rdi
callq 0x4860
cmpl $-0x1, (%rax)
je 0x12cea
movslq 0x1c4(%rsp), %rsi
leaq 0x2a0(%rsp), %rdi
callq 0x4860
movq %rax, 0x88(%rsp)
movq 0x2d0(%rsp), %rdi
movslq 0x1c4(%rsp), %rsi
callq 0x4860
movq 0x88(%rsp), %rsi
movq %rax, %rdx
leaq 0x1e0(%rsp), %rdi
callq 0xce90
jmp 0x12c83
jmp 0x12cea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x290(%rsp)
movl %eax, 0x28c(%rsp)
leaq 0x23e(%rsp), %rdi
callq 0x138d0
jmp 0x13577
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x290(%rsp)
movl %eax, 0x28c(%rsp)
jmp 0x1356a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x290(%rsp)
movl %eax, 0x28c(%rsp)
leaq 0x1e0(%rsp), %rdi
callq 0x4ae0
jmp 0x12f27
jmp 0x12cec
leaq 0x1d0(%rsp), %rdi
callq 0x4930
jmp 0x12be5
leaq 0x1e0(%rsp), %rdi
callq 0x13910
testb $0x1, %al
jne 0x12dc7
leaq 0x1e0(%rsp), %rdi
movq %rdi, 0x78(%rsp)
callq 0x7280
movq 0x78(%rsp), %rdi
movq %rax, 0x1a8(%rsp)
callq 0x7100
movq %rax, 0x1a0(%rsp)
movq 0x1a8(%rsp), %rdi
movq 0x1a0(%rsp), %rsi
callq 0x13960
movq %rax, 0x80(%rsp)
jmp 0x12d5e
movq 0x80(%rsp), %rax
movq %rax, 0x1b0(%rsp)
leaq 0x1b0(%rsp), %rdi
callq 0x9fb0
movq (%rax), %rax
movq %rax, 0x1bc(%rsp)
movl 0x1c0(%rsp), %eax
movl %eax, 0x74(%rsp)
movq 0x2d0(%rsp), %rdi
movslq 0x1fc(%rsp), %rsi
callq 0x4860
movl 0x74(%rsp), %ecx
movl %ecx, (%rax)
movslq 0x1fc(%rsp), %rsi
leaq 0x2a0(%rsp), %rdi
callq 0x4860
movl $0x0, (%rax)
leaq 0x1e0(%rsp), %rdi
callq 0x4ae0
movslq 0x1fc(%rsp), %rsi
leaq 0x2a0(%rsp), %rdi
callq 0x4860
cmpl $-0x1, (%rax)
je 0x12ead
movslq 0x1fc(%rsp), %rsi
leaq 0x2a0(%rsp), %rdi
callq 0x4860
cmpl $0x0, (%rax)
je 0x12e54
movq 0x1a1b5(%rip), %rax     # 0x2cfc8
movq (%rax), %rax
movq %rax, 0x68(%rsp)
movl 0x1fc(%rsp), %eax
movl %eax, 0x70(%rsp)
movslq 0x1fc(%rsp), %rsi
leaq 0x2a0(%rsp), %rdi
callq 0x4860
movq 0x68(%rsp), %rdi
movl 0x70(%rsp), %edx
movl (%rax), %ecx
leaq 0xe7de(%rip), %rsi      # 0x2162b
movb $0x0, %al
callq 0x2180
movl $0x0, 0x194(%rsp)
leaq 0x198(%rsp), %rdi
movq %rdi, 0x60(%rsp)
leaq 0x194(%rsp), %rsi
leaq 0x1fc(%rsp), %rdx
callq 0x13a10
movq 0x60(%rsp), %rsi
leaq 0x218(%rsp), %rdi
callq 0x139b0
jmp 0x12e95
jmp 0x12ead
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x290(%rsp)
movl %eax, 0x28c(%rsp)
jmp 0x12f27
jmp 0x12eaf
leaq 0x208(%rsp), %rdi
callq 0x4930
jmp 0x12ace
movq 0x2e0(%rsp), %rdi
movq 0x2d0(%rsp), %rdx
movl 0x2cc(%rsp), %r9d
movl 0x2c8(%rsp), %ecx
movq %rsp, %rax
movl %ecx, (%rax)
leaq 0x218(%rsp), %rsi
leaq 0x2a0(%rsp), %rcx
leaq 0x240(%rsp), %r8
callq 0x12270
jmp 0x12f04
leaq 0x218(%rsp), %rdi
callq 0x13a50
movl 0x238(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x238(%rsp)
jmp 0x12a63
leaq 0x218(%rsp), %rdi
callq 0x13a50
jmp 0x1356a
movq 0x2e0(%rsp), %rdi
addq $0x30, %rdi
callq 0x4880
movq %rax, 0x170(%rsp)
movq 0x2e0(%rsp), %rdi
addq $0x30, %rdi
callq 0x48b0
movq %rax, 0x168(%rsp)
leaq 0x167(%rsp), %rdi
movq %rdi, 0x58(%rsp)
callq 0x4f40
movq 0x58(%rsp), %rcx
movq 0x170(%rsp), %rsi
movq 0x168(%rsp), %rdx
leaq 0x178(%rsp), %rdi
callq 0x13a60
jmp 0x12fa1
leaq 0x167(%rsp), %rdi
callq 0x4fd0
movl $0x1, 0x160(%rsp)
movl 0x160(%rsp), %eax
cmpl 0x2c0(%rsp), %eax
jg 0x13429
leaq 0x140(%rsp), %rdi
callq 0x138e0
jmp 0x12fdc
movq 0x2e0(%rsp), %rdi
addq $0xa8, %rdi
movslq 0x160(%rsp), %rsi
callq 0x4a60
movq %rax, 0x138(%rsp)
movq 0x138(%rsp), %rdi
callq 0x4880
movq %rax, 0x130(%rsp)
movq 0x138(%rsp), %rdi
callq 0x48b0
movq %rax, 0x128(%rsp)
leaq 0x130(%rsp), %rdi
leaq 0x128(%rsp), %rsi
callq 0x48e0
testb $0x1, %al
jne 0x13048
jmp 0x1339d
leaq 0x130(%rsp), %rdi
callq 0x4920
movl (%rax), %eax
movl %eax, 0x124(%rsp)
movslq 0x124(%rsp), %rsi
leaq 0x2a0(%rsp), %rdi
callq 0x4860
cmpl $-0x1, (%rax)
jne 0x13389
movq 0x2e0(%rsp), %rdi
addq $0x78, %rdi
movslq 0x124(%rsp), %rsi
callq 0x4a60
movq %rax, %rdi
callq 0x86a0
testb $0x1, %al
jne 0x13389
leaq 0x108(%rsp), %rdi
callq 0x13af0
movq 0x2e0(%rsp), %rdi
addq $0x78, %rdi
movslq 0x124(%rsp), %rsi
callq 0x4a60
movq %rax, 0x100(%rsp)
movq 0x100(%rsp), %rdi
callq 0x4880
movq %rax, 0xf8(%rsp)
movq 0x100(%rsp), %rdi
callq 0x48b0
movq %rax, 0xf0(%rsp)
leaq 0xf8(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x48e0
testb $0x1, %al
jne 0x1311b
jmp 0x13238
leaq 0xf8(%rsp), %rdi
callq 0x4920
movl (%rax), %eax
movl %eax, 0xec(%rsp)
movslq 0xec(%rsp), %rsi
leaq 0x2a0(%rsp), %rdi
callq 0x4860
cmpl $-0x1, (%rax)
je 0x13224
movslq 0xec(%rsp), %rsi
leaq 0x178(%rsp), %rdi
callq 0x4860
movl (%rax), %eax
negl %eax
movl %eax, 0xe8(%rsp)
movslq 0xec(%rsp), %rsi
leaq 0x2a0(%rsp), %rdi
callq 0x4860
movq %rax, 0x50(%rsp)
movq 0x2d0(%rsp), %rdi
movslq 0xec(%rsp), %rsi
callq 0x4860
movq 0x50(%rsp), %rdx
movq %rax, %rcx
leaq 0x108(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x13b00
jmp 0x131bd
jmp 0x13224
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x290(%rsp)
movl %eax, 0x28c(%rsp)
leaq 0x167(%rsp), %rdi
callq 0x4fd0
jmp 0x1356a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x290(%rsp)
movl %eax, 0x28c(%rsp)
jmp 0x1355d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x290(%rsp)
movl %eax, 0x28c(%rsp)
leaq 0x108(%rsp), %rdi
callq 0x13d10
jmp 0x13417
jmp 0x13226
leaq 0xf8(%rsp), %rdi
callq 0x4930
jmp 0x130fd
leaq 0x108(%rsp), %rdi
callq 0x13b90
testb $0x1, %al
jne 0x1337c
leaq 0x108(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0x13c40
movq 0x40(%rsp), %rdi
movq %rax, 0xd0(%rsp)
callq 0x13c70
movq %rax, 0xc8(%rsp)
movq 0xd0(%rsp), %rdi
movq 0xc8(%rsp), %rsi
callq 0x13bf0
movq %rax, 0x48(%rsp)
jmp 0x13295
movq 0x48(%rsp), %rax
movq %rax, 0xd8(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0x13ca0
movq %rax, %rdi
callq 0x13be0
movl (%rax), %eax
movl %eax, 0xe4(%rsp)
movq 0x2d0(%rsp), %rdi
movslq 0xe4(%rsp), %rsi
callq 0x4860
movl (%rax), %eax
movl %eax, 0x24(%rsp)
movq 0x2d0(%rsp), %rdi
movslq 0x124(%rsp), %rsi
callq 0x4860
movl 0x24(%rsp), %ecx
movl %ecx, (%rax)
movslq 0x124(%rsp), %rsi
leaq 0x2a0(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x4860
movl $0x0, (%rax)
movslq 0xe4(%rsp), %rsi
leaq 0x178(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x4860
movq 0x28(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x34(%rsp)
movslq 0x124(%rsp), %rsi
callq 0x4860
movl 0x34(%rsp), %ecx
movq 0x38(%rsp), %rdi
movl %ecx, (%rax)
movslq 0x124(%rsp), %rsi
callq 0x4860
movq %rax, %rsi
leaq 0x140(%rsp), %rdi
leaq 0x124(%rsp), %rdx
callq 0x13cb0
jmp 0x1337a
jmp 0x1337c
leaq 0x108(%rsp), %rdi
callq 0x13d10
jmp 0x1338b
leaq 0x130(%rsp), %rdi
callq 0x4930
jmp 0x1302a
movq 0x2e0(%rsp), %rdi
movq 0x2d0(%rsp), %rdx
movl 0x2cc(%rsp), %r9d
movl 0x2c8(%rsp), %ecx
movq %rsp, %rax
movl %ecx, (%rax)
leaq 0x140(%rsp), %rsi
leaq 0x2a0(%rsp), %rcx
leaq 0x240(%rsp), %r8
callq 0x12270
jmp 0x133e0
leaq 0x140(%rsp), %rdi
callq 0x13a50
movl 0x160(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x160(%rsp)
jmp 0x12fb9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x290(%rsp)
movl %eax, 0x28c(%rsp)
leaq 0x140(%rsp), %rdi
callq 0x13a50
jmp 0x1355d
movl $0x0, 0xc4(%rsp)
movl 0xc4(%rsp), %eax
cmpl 0x2c4(%rsp), %eax
jge 0x1352e
movq 0x2e0(%rsp), %rdi
addq $0x18, %rdi
movslq 0xc4(%rsp), %rsi
callq 0x4970
cmpl $0x0, (%rax)
jne 0x13516
movq 0x2d0(%rsp), %rdi
movslq 0xc4(%rsp), %rsi
callq 0x4860
cmpl $-0x1, (%rax)
je 0x1349e
movslq 0xc4(%rsp), %rsi
leaq 0x2a0(%rsp), %rdi
callq 0x4860
cmpl $0x0, (%rax)
jge 0x13516
movq 0x19b23(%rip), %rax     # 0x2cfc8
movq (%rax), %rax
movq %rax, 0x10(%rsp)
movl 0xc4(%rsp), %eax
movl %eax, 0x18(%rsp)
movq 0x2d0(%rsp), %rdi
movslq 0xc4(%rsp), %rsi
callq 0x4860
movl (%rax), %eax
movl %eax, 0x1c(%rsp)
movl 0xc4(%rsp), %eax
movl %eax, 0x20(%rsp)
movslq 0xc4(%rsp), %rsi
leaq 0x2a0(%rsp), %rdi
callq 0x4860
movq 0x10(%rsp), %rdi
movl 0x18(%rsp), %edx
movl 0x1c(%rsp), %ecx
movl 0x20(%rsp), %r8d
movl (%rax), %r9d
leaq 0xe145(%rip), %rsi      # 0x21654
movb $0x0, %al
callq 0x2180
jmp 0x13518
movl 0xc4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc4(%rsp)
jmp 0x13434
leaq 0x178(%rsp), %rdi
callq 0x5020
leaq 0x240(%rsp), %rdi
callq 0x13d70
leaq 0x2a0(%rsp), %rdi
callq 0x5020
addq $0x2e8, %rsp            # imm = 0x2E8
retq
leaq 0x178(%rsp), %rdi
callq 0x5020
leaq 0x240(%rsp), %rdi
callq 0x13d70
leaq 0x2a0(%rsp), %rdi
callq 0x5020
movq 0x290(%rsp), %rdi
callq 0x21f0
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)