// File: yogesh1q2w[P]Dynamic-Graph-Algorithms/SPT.cpp
// Function: SPT::modify_dec(int, int, int, int)
void SPT::modify_dec(int u, int v, int oldwt, int diff) {
    
    multiset<pair<int,pair<int,int>>> Q;
    
    vector<pair<int,int>> treeadj[spt.size()];
    int root;// get adjacency list representation of tree
    for (int i = 0; i < spt.size(); i++) { 
        if (spt[i].first == -1) 
            root = i; 
        else
            treeadj[spt[i].first].push_back(make_pair(i,spt[i].second));
    }

    vector<int> desc_v;
    descendants(v,desc_v,treeadj);
    for(auto &d: desc_v) {
        dist[d] += diff;
        for(auto &j:adj[d]) {
            int min_inc = dist[d] + weight[make_pair(d,j)] - dist[j];
            if(min_inc < 0)
                Q.insert(make_pair(min_inc,make_pair(d,j)));
        }
    }

    while(!Q.empty()) {
        pair<int,pair<int,int>> e1 = *(Q.begin());
        Q.erase(Q.begin());
        spt[e1.second.second] = make_pair(e1.second.first,weight[e1.second]);
        treeadj[e1.second.first].push_back(make_pair(e1.second.second,e1.first));
        vector<int> desc_end_e1;
        descendants(e1.second.second,desc_end_e1,treeadj);
        for(auto &i:desc_end_e1) {
            dist[i] = dist[i] + e1.first;
        }
        for(auto &i:Q) {
            if(find(desc_end_e1.begin(), desc_end_e1.end(), i.second.second) != desc_end_e1.end())
                Q.erase(i);
        }

        for(auto &i:desc_end_e1) {
            for(auto &j:adj[i]) {
                if(find(desc_end_e1.begin(),desc_end_e1.end(),j) == desc_end_e1.end()) {
                    int min_inc = dist[i] + weight[make_pair(i,j)] - dist[j];
                    if(min_inc < 0) {
                        Q.insert(make_pair(min_inc,make_pair(i,j)));
                    }
                }
            }
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x3e0, %rsp            # imm = 0x3E0
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl %r8d, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x268(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x202a0
movq -0x268(%rbp), %rdi
addq $0xe0, %rdi
callq 0x1af90
movq %rax, %rcx
movq %rcx, %rax
movq %rax, -0x260(%rbp)
movq %rsp, %rdx
movq %rdx, -0x50(%rbp)
leaq (%rcx,%rcx,2), %rcx
leaq 0xf(,%rcx,8), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x258(%rbp)
movq %rcx, %rsp
movq %rax, -0x58(%rbp)
cmpq $0x0, %rax
je 0x1f198
movq -0x258(%rbp), %rax
movq -0x260(%rbp), %rcx
imulq $0x18, %rcx, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, -0x278(%rbp)
movq %rax, -0x270(%rbp)
movq -0x270(%rbp), %rdi
movq %rdi, -0x280(%rbp)
callq 0x1a3d0
movq -0x280(%rbp), %rax
movq -0x278(%rbp), %rcx
addq $0x18, %rax
cmpq %rcx, %rax
movq %rax, -0x270(%rbp)
jne 0x1f167
movl $0x0, -0x60(%rbp)
movq -0x268(%rbp), %rdi
movslq -0x60(%rbp), %rax
movq %rax, -0x288(%rbp)
addq $0xe0, %rdi
callq 0x1af90
movq %rax, %rcx
movq -0x288(%rbp), %rax
cmpq %rcx, %rax
jae 0x1f29a
movq -0x268(%rbp), %rdi
addq $0xe0, %rdi
movslq -0x60(%rbp), %rsi
callq 0x20150
cmpl $-0x1, (%rax)
jne 0x1f1f7
movl -0x60(%rbp), %eax
movl %eax, -0x5c(%rbp)
jmp 0x1f28a
movq -0x268(%rbp), %rdi
addq $0xe0, %rdi
movq %rdi, -0x2a0(%rbp)
movslq -0x60(%rbp), %rsi
callq 0x20150
movq -0x2a0(%rbp), %rdi
movq %rax, %rcx
movq -0x258(%rbp), %rax
movslq (%rcx), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rax
movq %rax, -0x298(%rbp)
movslq -0x60(%rbp), %rsi
callq 0x20150
movq %rax, %rsi
addq $0x4, %rsi
leaq -0x60(%rbp), %rdi
callq 0x3520
movq %rax, -0x290(%rbp)
jmp 0x1f25a
movq -0x298(%rbp), %rdi
movq -0x290(%rbp), %rax
movq %rax, -0x68(%rbp)
leaq -0x68(%rbp), %rsi
callq 0x14b80
jmp 0x1f277
jmp 0x1f28a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x1fcd1
jmp 0x1f28c
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x1f19f
leaq -0x90(%rbp), %rdi
movq %rdi, -0x2a8(%rbp)
callq 0x1fe30
movq -0x268(%rbp), %rdi
movq -0x2a8(%rbp), %rdx
movq -0x258(%rbp), %rcx
movl -0x10(%rbp), %esi
callq 0x1fd40
jmp 0x1f2cc
leaq -0x90(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rdi
callq 0x1fff0
movq %rax, -0xa0(%rbp)
movq -0x98(%rbp), %rdi
callq 0x20020
movq %rax, -0xa8(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x20170
testb $0x1, %al
jne 0x1f31c
jmp 0x1f594
leaq -0xa0(%rbp), %rdi
callq 0x201b0
movq -0x268(%rbp), %rdi
movq %rax, -0xb0(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x2b4(%rbp)
addq $0xf8, %rdi
movq -0xb0(%rbp), %rax
movslq (%rax), %rsi
callq 0x15120
movl -0x2b4(%rbp), %edx
movq -0x268(%rbp), %rdi
movl (%rax), %ecx
addl %edx, %ecx
movl %ecx, (%rax)
addq $0x70, %rdi
movq -0xb0(%rbp), %rsi
callq 0x1fe50
movq %rax, -0x2b0(%rbp)
jmp 0x1f381
movq -0x2b0(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rdi
callq 0x1fff0
movq %rax, -0xc0(%rbp)
movq -0xb8(%rbp), %rdi
callq 0x20020
movq %rax, -0xc8(%rbp)
leaq -0xc0(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x20170
testb $0x1, %al
jne 0x1f3d1
jmp 0x1f581
leaq -0xc0(%rbp), %rdi
callq 0x201b0
movq -0x268(%rbp), %rdi
movq %rax, -0xd0(%rbp)
addq $0xf8, %rdi
movq -0xb0(%rbp), %rax
movslq (%rax), %rsi
callq 0x15120
movq %rax, %rcx
movq -0x268(%rbp), %rax
movl (%rcx), %ecx
movl %ecx, -0x2cc(%rbp)
addq $0x8, %rax
movq %rax, -0x2c8(%rbp)
movq -0xb0(%rbp), %rdi
movq -0xd0(%rbp), %rsi
callq 0x3520
movq %rax, -0x2c0(%rbp)
jmp 0x1f43a
movq -0x2c8(%rbp), %rdi
movq -0x2c0(%rbp), %rax
movq %rax, -0xdc(%rbp)
leaq -0xdc(%rbp), %rsi
callq 0x14aa0
movq %rax, -0x2d8(%rbp)
jmp 0x1f464
movq -0x268(%rbp), %rdi
movq -0x2d8(%rbp), %rcx
movl -0x2cc(%rbp), %eax
addl (%rcx), %eax
movl %eax, -0x2dc(%rbp)
addq $0xf8, %rdi
movq -0xd0(%rbp), %rax
movslq (%rax), %rsi
callq 0x15120
movq %rax, %rcx
movl -0x2dc(%rbp), %eax
subl (%rcx), %eax
movl %eax, -0xd4(%rbp)
cmpl $0x0, -0xd4(%rbp)
jge 0x1f56e
movq -0xb0(%rbp), %rdi
movq -0xd0(%rbp), %rsi
callq 0x3520
movq %rax, -0x2e8(%rbp)
jmp 0x1f4d0
movq -0x2e8(%rbp), %rax
movq %rax, -0xf0(%rbp)
leaq -0xd4(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x20300
movl %edx, -0x2f4(%rbp)
movq %rax, -0x2f0(%rbp)
jmp 0x1f500
movl -0x2f4(%rbp), %eax
movq -0x2f0(%rbp), %rcx
movq %rcx, -0x100(%rbp)
movl %eax, -0xf8(%rbp)
movl -0xf8(%rbp), %eax
movl %eax, -0xe0(%rbp)
movq -0x100(%rbp), %rax
movq %rax, -0xe8(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x202c0
movq %rax, -0x300(%rbp)
jmp 0x1f54d
movq -0x300(%rbp), %rax
movq %rax, -0x108(%rbp)
jmp 0x1f56e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x1fcc5
jmp 0x1f570
leaq -0xc0(%rbp), %rdi
callq 0x201d0
jmp 0x1f3b5
jmp 0x1f583
leaq -0xa0(%rbp), %rdi
callq 0x201d0
jmp 0x1f300
jmp 0x1f596
leaq -0x48(%rbp), %rdi
callq 0x20450
xorb $-0x1, %al
testb $0x1, %al
jne 0x1f5aa
jmp 0x1fc4f
leaq -0x48(%rbp), %rdi
movq %rdi, -0x310(%rbp)
callq 0x20470
movq %rax, -0x120(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x204a0
movq -0x310(%rbp), %rdi
movl 0x8(%rax), %ecx
movl %ecx, -0x110(%rbp)
movq (%rax), %rax
movq %rax, -0x118(%rbp)
callq 0x20470
movq -0x310(%rbp), %rdi
movq %rax, -0x128(%rbp)
movq -0x128(%rbp), %rsi
callq 0x204c0
movq %rax, -0x308(%rbp)
jmp 0x1f60f
movq -0x268(%rbp), %rdi
movq -0x308(%rbp), %rax
movq %rax, -0x130(%rbp)
leaq -0x114(%rbp), %rsi
movq %rsi, -0x320(%rbp)
addq $0x8, %rdi
callq 0x20500
movq %rax, -0x318(%rbp)
jmp 0x1f644
movq -0x318(%rbp), %rsi
movq -0x320(%rbp), %rdi
callq 0x3520
movq %rax, -0x328(%rbp)
jmp 0x1f660
movq -0x268(%rbp), %rdi
movq -0x328(%rbp), %rax
movq %rax, -0x138(%rbp)
addq $0xe0, %rdi
leaq -0x110(%rbp), %rax
movq %rax, -0x340(%rbp)
movslq -0x110(%rbp), %rsi
callq 0x20150
movq %rax, %rdi
leaq -0x138(%rbp), %rsi
callq 0x1cec0
movq -0x340(%rbp), %rdi
movq -0x258(%rbp), %rax
movslq -0x114(%rbp), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rax
movq %rax, -0x338(%rbp)
leaq -0x118(%rbp), %rsi
callq 0x3520
movq %rax, -0x330(%rbp)
jmp 0x1f6de
movq -0x338(%rbp), %rdi
movq -0x330(%rbp), %rax
movq %rax, -0x140(%rbp)
leaq -0x140(%rbp), %rsi
callq 0x14b80
jmp 0x1f701
leaq -0x158(%rbp), %rdi
movq %rdi, -0x348(%rbp)
callq 0x1fe30
movq -0x268(%rbp), %rdi
movq -0x348(%rbp), %rdx
movq -0x258(%rbp), %rcx
movl -0x110(%rbp), %esi
callq 0x1fd40
jmp 0x1f736
leaq -0x158(%rbp), %rax
movq %rax, -0x160(%rbp)
movq -0x160(%rbp), %rdi
callq 0x1fff0
movq %rax, -0x168(%rbp)
movq -0x160(%rbp), %rdi
callq 0x20020
movq %rax, -0x170(%rbp)
leaq -0x168(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x20170
testb $0x1, %al
jne 0x1f786
jmp 0x1f817
leaq -0x168(%rbp), %rdi
callq 0x201b0
movq -0x268(%rbp), %rdi
movq %rax, -0x178(%rbp)
addq $0xf8, %rdi
movq -0x178(%rbp), %rax
movslq (%rax), %rsi
callq 0x15120
movq -0x268(%rbp), %rdi
movl (%rax), %eax
addl -0x118(%rbp), %eax
movl %eax, -0x34c(%rbp)
addq $0xf8, %rdi
movq -0x178(%rbp), %rax
movslq (%rax), %rsi
callq 0x15120
movl -0x34c(%rbp), %ecx
movl %ecx, (%rax)
leaq -0x168(%rbp), %rdi
callq 0x201d0
jmp 0x1f76a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x158(%rbp), %rdi
callq 0x154a0
jmp 0x1fcc5
leaq -0x48(%rbp), %rax
movq %rax, -0x180(%rbp)
movq -0x180(%rbp), %rdi
callq 0x20470
movq %rax, -0x188(%rbp)
movq -0x180(%rbp), %rdi
callq 0x20560
movq %rax, -0x190(%rbp)
leaq -0x188(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0x20590
testb $0x1, %al
jne 0x1f864
jmp 0x1f92c
leaq -0x188(%rbp), %rdi
callq 0x204a0
movq %rax, -0x198(%rbp)
leaq -0x158(%rbp), %rdi
movq %rdi, -0x360(%rbp)
callq 0x1fff0
movq -0x360(%rbp), %rdi
movq %rax, -0x1a8(%rbp)
callq 0x20020
movq %rax, -0x1b0(%rbp)
movq -0x198(%rbp), %rdx
addq $0x8, %rdx
movq -0x1a8(%rbp), %rdi
movq -0x1b0(%rbp), %rsi
callq 0x20380
movq %rax, -0x358(%rbp)
jmp 0x1f8cb
movq -0x358(%rbp), %rax
movq %rax, -0x1a0(%rbp)
leaq -0x158(%rbp), %rdi
callq 0x20020
movq %rax, -0x1b8(%rbp)
leaq -0x1a0(%rbp), %rdi
leaq -0x1b8(%rbp), %rsi
callq 0x20170
testb $0x1, %al
jne 0x1f905
jmp 0x1f919
movq -0x198(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x205c0
jmp 0x1f917
jmp 0x1f919
jmp 0x1f91b
leaq -0x188(%rbp), %rdi
callq 0x205f0
jmp 0x1f848
leaq -0x158(%rbp), %rax
movq %rax, -0x1c0(%rbp)
movq -0x1c0(%rbp), %rdi
callq 0x1fff0
movq %rax, -0x1c8(%rbp)
movq -0x1c0(%rbp), %rdi
callq 0x20020
movq %rax, -0x1d0(%rbp)
leaq -0x1c8(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
callq 0x20170
testb $0x1, %al
jne 0x1f97c
jmp 0x1fc3e
leaq -0x1c8(%rbp), %rdi
callq 0x201b0
movq -0x268(%rbp), %rdi
movq %rax, -0x1d8(%rbp)
addq $0x70, %rdi
movq -0x1d8(%rbp), %rsi
callq 0x1fe50
movq %rax, -0x368(%rbp)
jmp 0x1f9af
movq -0x368(%rbp), %rax
movq %rax, -0x1e0(%rbp)
movq -0x1e0(%rbp), %rdi
callq 0x1fff0
movq %rax, -0x1e8(%rbp)
movq -0x1e0(%rbp), %rdi
callq 0x20020
movq %rax, -0x1f0(%rbp)
leaq -0x1e8(%rbp), %rdi
leaq -0x1f0(%rbp), %rsi
callq 0x20170
testb $0x1, %al
jne 0x1f9ff
jmp 0x1fc2b
leaq -0x1e8(%rbp), %rdi
callq 0x201b0
movq %rax, -0x1f8(%rbp)
leaq -0x158(%rbp), %rdi
movq %rdi, -0x378(%rbp)
callq 0x1fff0
movq -0x378(%rbp), %rdi
movq %rax, -0x208(%rbp)
callq 0x20020
movq %rax, -0x210(%rbp)
movq -0x1f8(%rbp), %rdx
movq -0x208(%rbp), %rdi
movq -0x210(%rbp), %rsi
callq 0x20380
movq %rax, -0x370(%rbp)
jmp 0x1fa62
movq -0x370(%rbp), %rax
movq %rax, -0x200(%rbp)
leaq -0x158(%rbp), %rdi
callq 0x20020
movq %rax, -0x218(%rbp)
leaq -0x200(%rbp), %rdi
leaq -0x218(%rbp), %rsi
callq 0x20340
testb $0x1, %al
jne 0x1fa9f
jmp 0x1fc18
movq -0x268(%rbp), %rdi
addq $0xf8, %rdi
movq -0x1d8(%rbp), %rax
movslq (%rax), %rsi
callq 0x15120
movq %rax, %rcx
movq -0x268(%rbp), %rax
movl (%rcx), %ecx
movl %ecx, -0x38c(%rbp)
addq $0x8, %rax
movq %rax, -0x388(%rbp)
movq -0x1d8(%rbp), %rdi
movq -0x1f8(%rbp), %rsi
callq 0x3520
movq %rax, -0x380(%rbp)
jmp 0x1faf5
movq -0x388(%rbp), %rdi
movq -0x380(%rbp), %rax
movq %rax, -0x224(%rbp)
leaq -0x224(%rbp), %rsi
callq 0x14aa0
movq %rax, -0x398(%rbp)
jmp 0x1fb1f
movq -0x268(%rbp), %rdi
movq -0x398(%rbp), %rcx
movl -0x38c(%rbp), %eax
addl (%rcx), %eax
movl %eax, -0x39c(%rbp)
addq $0xf8, %rdi
movq -0x1f8(%rbp), %rax
movslq (%rax), %rsi
callq 0x15120
movq %rax, %rcx
movl -0x39c(%rbp), %eax
subl (%rcx), %eax
movl %eax, -0x21c(%rbp)
cmpl $0x0, -0x21c(%rbp)
jge 0x1fc16
movq -0x1d8(%rbp), %rdi
movq -0x1f8(%rbp), %rsi
callq 0x3520
movq %rax, -0x3a8(%rbp)
jmp 0x1fb8b
movq -0x3a8(%rbp), %rax
movq %rax, -0x238(%rbp)
leaq -0x21c(%rbp), %rdi
leaq -0x238(%rbp), %rsi
callq 0x20300
movl %edx, -0x3b4(%rbp)
movq %rax, -0x3b0(%rbp)
jmp 0x1fbbb
movl -0x3b4(%rbp), %eax
movq -0x3b0(%rbp), %rcx
movq %rcx, -0x248(%rbp)
movl %eax, -0x240(%rbp)
movl -0x240(%rbp), %eax
movl %eax, -0x228(%rbp)
movq -0x248(%rbp), %rax
movq %rax, -0x230(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x230(%rbp), %rsi
callq 0x202c0
movq %rax, -0x3c0(%rbp)
jmp 0x1fc08
movq -0x3c0(%rbp), %rax
movq %rax, -0x250(%rbp)
jmp 0x1fc18
jmp 0x1fc1a
leaq -0x1e8(%rbp), %rdi
callq 0x201d0
jmp 0x1f9e3
jmp 0x1fc2d
leaq -0x1c8(%rbp), %rdi
callq 0x201d0
jmp 0x1f960
leaq -0x158(%rbp), %rdi
callq 0x154a0
jmp 0x1f596
leaq -0x90(%rbp), %rdi
callq 0x154a0
movq -0x260(%rbp), %rax
movq -0x258(%rbp), %rcx
imulq $0x18, %rax, %rdx
movq %rcx, %rax
addq %rdx, %rax
cmpq %rax, %rcx
movq %rax, -0x3c8(%rbp)
je 0x1fcb0
movq -0x3c8(%rbp), %rdi
addq $-0x18, %rdi
movq %rdi, -0x3d0(%rbp)
callq 0x16330
movq -0x258(%rbp), %rcx
movq -0x3d0(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x3c8(%rbp)
jne 0x1fc7f
movq -0x50(%rbp), %rax
movq %rax, %rsp
leaq -0x48(%rbp), %rdi
callq 0x20750
movq %rbp, %rsp
popq %rbp
retq
leaq -0x90(%rbp), %rdi
callq 0x154a0
movq -0x258(%rbp), %rcx
movq -0x260(%rbp), %rax
imulq $0x18, %rax, %rdx
movq %rcx, %rax
addq %rdx, %rax
cmpq %rax, %rcx
movq %rax, -0x3d8(%rbp)
je 0x1fd26
movq -0x3d8(%rbp), %rdi
addq $-0x18, %rdi
movq %rdi, -0x3e0(%rbp)
callq 0x16330
movq -0x258(%rbp), %rcx
movq -0x3e0(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x3d8(%rbp)
jne 0x1fcf5
leaq -0x48(%rbp), %rdi
callq 0x20750
movq -0x70(%rbp), %rdi
callq 0x2250
nopl (%rax,%rax)