// File: todo314[P]pruned-monte-carlo/src/pmc.cpp
// Function: InfluenceMaximizer::run(std::vector<std::pair<std::pair<int, int>, double>, std::allocator<std::pair<std::pair<int, int>, double>>>&, int, int)
vector<int> InfluenceMaximizer::run(vector<pair<pair<int, int>, double> > &es,
		const int k, const int R) {
	n = 0;
	m = es.size();
	for (int i = 0; i < (int) es.size(); i++) {
		n = max(n, max(es[i].first.first, es[i].first.second) + 1);
	}

	sort(es.begin(), es.end());

	es1.resize(m);
	rs1.resize(m);
	at_e.resize(n + 1);
	at_r.resize(n + 1);

	vector<PrunedEstimater> infs(R);
	vector<int> seeds;

	for (int t = 0; t < R; t++) {
		Xorshift xs = Xorshift(t);

		int mp = 0;
		at_e.assign(n + 1, 0);
		at_r.assign(n + 1, 0);
		vector<pair<int, int> > ps;
		for (int i = 0; i < m; i++) {
			if (xs.gen_double() < es[i].second) {
				es1[mp++] = es[i].first.second;
				at_e[es[i].first.first + 1]++;
				ps.push_back(make_pair(es[i].first.second, es[i].first.first));
			}
		}
		at_e[0] = 0;
		sort(ps.begin(), ps.end());
		for (int i = 0; i < mp; i++) {
			rs1[i] = ps[i].second;
			at_r[ps[i].first + 1]++;
		}
		for (int i = 1; i <= n; i++) {
			at_e[i] += at_e[i - 1];
			at_r[i] += at_r[i - 1];
		}

		vector<int> comp(n);

		int nscc = scc(comp);

		vector<pair<int, int> > es2;
		for (int u = 0; u < n; u++) {
			int a = comp[u];
			for (int i = at_e[u]; i < at_e[u + 1]; i++) {
				int b = comp[es1[i]];
				if (a != b) {
					es2.push_back(make_pair(a, b));
				}
			}
		}

		sort(es2.begin(), es2.end());
		es2.erase(unique(es2.begin(), es2.end()), es2.end());

		infs[t].init(nscc, es2, comp);
	}

	vector<long long> gain(n);
	vector<int> S;

	for (int t = 0; t < k; t++) {
		for (int j = 0; j < R; j++) {
			infs[j].update(gain);
		}
		int next = 0;
		for (int i = 0; i < n; i++) {
			if (gain[i] > gain[next]) {
				next = i;
			}
		}

		S.push_back(next);
		for (int j = 0; j < R; j++) {
			infs[j].add(next);
		}
		seeds.push_back(next);
	}
	return seeds;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x290, %rsp            # imm = 0x290
movq %rdi, -0x1c8(%rbp)
movq %rdi, %rax
movq %rax, -0x1c0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x1b8(%rbp)
movl $0x0, (%rax)
movq -0x18(%rbp), %rdi
callq 0x3610
movq %rax, %rcx
movq -0x1b8(%rbp), %rax
movl %ecx, 0x4(%rax)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x1cc(%rbp)
movq -0x18(%rbp), %rdi
callq 0x3610
movq %rax, %rcx
movl -0x1cc(%rbp), %eax
cmpl %ecx, %eax
jge 0x6034
movq -0x18(%rbp), %rdi
movslq -0x24(%rbp), %rsi
callq 0x7cb0
movq %rax, -0x1d8(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x24(%rbp), %rsi
callq 0x7cb0
movq -0x1d8(%rbp), %rdi
movq %rax, %rsi
addq $0x4, %rsi
callq 0x7c70
movq -0x1b8(%rbp), %rdi
movl (%rax), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
leaq -0x28(%rbp), %rsi
callq 0x7c70
movq %rax, %rcx
movq -0x1b8(%rbp), %rax
movl (%rcx), %ecx
movl %ecx, (%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x5fad
movq -0x18(%rbp), %rdi
callq 0x3510
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rdi
callq 0x3350
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x7cd0
movq -0x1b8(%rbp), %rax
movq %rax, %rdi
addq $0x8, %rdi
movslq 0x4(%rax), %rsi
callq 0x7490
movq -0x1b8(%rbp), %rax
movq %rax, %rdi
addq $0x38, %rdi
movslq 0x4(%rax), %rsi
callq 0x7490
movq -0x1b8(%rbp), %rax
movq %rax, %rdi
addq $0x20, %rdi
movl (%rax), %eax
incl %eax
movslq %eax, %rsi
callq 0x7490
movq -0x1b8(%rbp), %rax
movq %rax, %rdi
addq $0x50, %rdi
movl (%rax), %eax
incl %eax
movslq %eax, %rsi
callq 0x7490
movslq -0x20(%rbp), %rax
movq %rax, -0x1e8(%rbp)
leaq -0x51(%rbp), %rdi
movq %rdi, -0x1e0(%rbp)
callq 0x7d10
movq -0x1e8(%rbp), %rsi
movq -0x1e0(%rbp), %rdx
leaq -0x50(%rbp), %rdi
callq 0x7d30
jmp 0x60f1
leaq -0x51(%rbp), %rdi
callq 0x7da0
movq -0x1c8(%rbp), %rdi
movb $0x0, -0x65(%rbp)
callq 0x2c00
movl $0x0, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x6877
movl -0x6c(%rbp), %esi
leaq -0x7c(%rbp), %rdi
callq 0x7dc0
jmp 0x612b
movq -0x1b8(%rbp), %rax
movl $0x0, -0x80(%rbp)
movq %rax, %rdi
addq $0x20, %rdi
movl (%rax), %eax
incl %eax
movslq %eax, %rsi
movl $0x0, -0x84(%rbp)
leaq -0x84(%rbp), %rdx
callq 0x7e30
jmp 0x615f
movq -0x1b8(%rbp), %rax
movq %rax, %rdi
addq $0x50, %rdi
movl (%rax), %eax
incl %eax
movslq %eax, %rsi
movl $0x0, -0x88(%rbp)
leaq -0x88(%rbp), %rdx
callq 0x7e30
jmp 0x618c
leaq -0xa0(%rbp), %rdi
callq 0x7770
movl $0x0, -0xa4(%rbp)
movq -0x1b8(%rbp), %rcx
movl -0xa4(%rbp), %eax
cmpl 0x4(%rcx), %eax
jge 0x6326
leaq -0x7c(%rbp), %rdi
callq 0x7e60
movsd %xmm0, -0x1f0(%rbp)
jmp 0x61cb
movq -0x18(%rbp), %rdi
movslq -0xa4(%rbp), %rsi
callq 0x7cb0
movsd -0x1f0(%rbp), %xmm1
movsd 0x8(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x6310
movq -0x18(%rbp), %rdi
movslq -0xa4(%rbp), %rsi
callq 0x7cb0
movq -0x1b8(%rbp), %rdi
movl 0x4(%rax), %eax
movl %eax, -0x20c(%rbp)
addq $0x8, %rdi
movslq -0x80(%rbp), %rsi
movl %esi, %eax
incl %eax
movl %eax, -0x80(%rbp)
callq 0x29c0
movl -0x20c(%rbp), %edx
movq %rax, %rcx
movq -0x1b8(%rbp), %rax
movl %edx, (%rcx)
addq $0x20, %rax
movq %rax, -0x208(%rbp)
movq -0x18(%rbp), %rdi
movslq -0xa4(%rbp), %rsi
callq 0x7cb0
movq -0x208(%rbp), %rdi
movl (%rax), %eax
incl %eax
movslq %eax, %rsi
callq 0x29c0
movl (%rax), %ecx
incl %ecx
movl %ecx, (%rax)
movq -0x18(%rbp), %rdi
movslq -0xa4(%rbp), %rsi
callq 0x7cb0
addq $0x4, %rax
movq %rax, -0x200(%rbp)
movq -0x18(%rbp), %rdi
movslq -0xa4(%rbp), %rsi
callq 0x7cb0
movq -0x200(%rbp), %rdi
movq %rax, %rsi
callq 0x2940
movq %rax, -0x1f8(%rbp)
jmp 0x62af
movq -0x1f8(%rbp), %rax
movq %rax, -0xac(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0xac(%rbp), %rsi
callq 0x7790
jmp 0x62d2
jmp 0x6310
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x51(%rbp), %rdi
callq 0x7da0
jmp 0x6ade
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x6ac9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x6866
jmp 0x6312
movl -0xa4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa4(%rbp)
jmp 0x61a2
movq -0x1b8(%rbp), %rdi
addq $0x20, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x29c0
movl $0x0, (%rax)
leaq -0xa0(%rbp), %rdi
movq %rdi, -0x218(%rbp)
callq 0x7800
movq -0x218(%rbp), %rdi
movq %rax, -0xb8(%rbp)
callq 0x7830
movq %rax, -0xc0(%rbp)
movq -0xb8(%rbp), %rdi
movq -0xc0(%rbp), %rsi
callq 0x77c0
jmp 0x6382
movl $0x0, -0xc4(%rbp)
movl -0xc4(%rbp), %eax
cmpl -0x80(%rbp), %eax
jge 0x642d
movslq -0xc4(%rbp), %rsi
leaq -0xa0(%rbp), %rdi
callq 0x73c0
movq -0x1b8(%rbp), %rdi
movl 0x4(%rax), %eax
movl %eax, -0x224(%rbp)
addq $0x38, %rdi
movslq -0xc4(%rbp), %rsi
callq 0x29c0
movl -0x224(%rbp), %edx
movq %rax, %rcx
movq -0x1b8(%rbp), %rax
movl %edx, (%rcx)
addq $0x50, %rax
movq %rax, -0x220(%rbp)
movslq -0xc4(%rbp), %rsi
leaq -0xa0(%rbp), %rdi
callq 0x73c0
movq -0x220(%rbp), %rdi
movl (%rax), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x29c0
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movl -0xc4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc4(%rbp)
jmp 0x638c
movl $0x1, -0xc8(%rbp)
movq -0x1b8(%rbp), %rcx
movl -0xc8(%rbp), %eax
cmpl (%rcx), %eax
jg 0x64ea
movq -0x1b8(%rbp), %rdi
addq $0x20, %rdi
movl -0xc8(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x29c0
movq -0x1b8(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x22c(%rbp)
addq $0x20, %rdi
movslq -0xc8(%rbp), %rsi
callq 0x29c0
movl -0x22c(%rbp), %ecx
movq -0x1b8(%rbp), %rdi
addl (%rax), %ecx
movl %ecx, (%rax)
addq $0x50, %rdi
movl -0xc8(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x29c0
movq -0x1b8(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x228(%rbp)
addq $0x50, %rdi
movslq -0xc8(%rbp), %rsi
callq 0x29c0
movl -0x228(%rbp), %ecx
addl (%rax), %ecx
movl %ecx, (%rax)
movl -0xc8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc8(%rbp)
jmp 0x6437
movq -0x1b8(%rbp), %rax
movslq (%rax), %rax
movq %rax, -0x240(%rbp)
leaq -0xe1(%rbp), %rdi
movq %rdi, -0x238(%rbp)
callq 0x2c70
movq -0x240(%rbp), %rsi
movq -0x238(%rbp), %rdx
leaq -0xe0(%rbp), %rdi
callq 0x7350
jmp 0x652a
leaq -0xe1(%rbp), %rdi
callq 0x3b90
movq -0x1b8(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x6af0
movl %eax, -0x244(%rbp)
jmp 0x6551
movl -0x244(%rbp), %eax
movl %eax, -0xe8(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x7770
movl $0x0, -0x104(%rbp)
movq -0x1b8(%rbp), %rcx
movl -0x104(%rbp), %eax
cmpl (%rcx), %eax
jge 0x66f3
movslq -0x104(%rbp), %rsi
leaq -0xe0(%rbp), %rdi
callq 0x29c0
movq -0x1b8(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x108(%rbp)
addq $0x20, %rdi
movslq -0x104(%rbp), %rsi
callq 0x29c0
movl (%rax), %eax
movl %eax, -0x10c(%rbp)
movq -0x1b8(%rbp), %rdi
movl -0x10c(%rbp), %eax
movl %eax, -0x248(%rbp)
addq $0x20, %rdi
movl -0x104(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x29c0
movq %rax, %rcx
movl -0x248(%rbp), %eax
cmpl (%rcx), %eax
jge 0x66dd
movq -0x1b8(%rbp), %rdi
addq $0x8, %rdi
movslq -0x10c(%rbp), %rsi
callq 0x29c0
movslq (%rax), %rsi
leaq -0xe0(%rbp), %rdi
callq 0x29c0
movl (%rax), %eax
movl %eax, -0x110(%rbp)
movl -0x108(%rbp), %eax
cmpl -0x110(%rbp), %eax
je 0x66c7
leaq -0x108(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x2940
movq %rax, -0x250(%rbp)
jmp 0x6657
movq -0x250(%rbp), %rax
movq %rax, -0x118(%rbp)
leaq -0x100(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x7790
jmp 0x667a
jmp 0x66c7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0xe1(%rbp), %rdi
callq 0x3b90
jmp 0x6866
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x685a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x78d0
jmp 0x685a
jmp 0x66c9
movl -0x10c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10c(%rbp)
jmp 0x65c2
jmp 0x66df
movl -0x104(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x104(%rbp)
jmp 0x6573
leaq -0x100(%rbp), %rdi
movq %rdi, -0x258(%rbp)
callq 0x7800
movq -0x258(%rbp), %rdi
movq %rax, -0x120(%rbp)
callq 0x7830
movq %rax, -0x128(%rbp)
movq -0x120(%rbp), %rdi
movq -0x128(%rbp), %rsi
callq 0x77c0
jmp 0x6735
leaq -0x100(%rbp), %rdi
movq %rdi, -0x268(%rbp)
callq 0x7800
movq -0x268(%rbp), %rdi
movq %rax, -0x140(%rbp)
callq 0x7830
movq %rax, -0x148(%rbp)
movq -0x140(%rbp), %rdi
movq -0x148(%rbp), %rsi
callq 0x7f50
movq %rax, -0x260(%rbp)
jmp 0x677e
movq -0x260(%rbp), %rax
movq %rax, -0x138(%rbp)
leaq -0x130(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x7f90
leaq -0x100(%rbp), %rdi
movq %rdi, -0x278(%rbp)
callq 0x7830
movq %rax, -0x158(%rbp)
leaq -0x150(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0x7f90
movq -0x278(%rbp), %rdi
movq -0x130(%rbp), %rsi
movq -0x150(%rbp), %rdx
callq 0x7ec0
movq %rax, -0x270(%rbp)
jmp 0x67ef
movq -0x270(%rbp), %rax
movq %rax, -0x160(%rbp)
movslq -0x6c(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x7fd0
movq %rax, %rdi
movl -0xe8(%rbp), %esi
leaq -0x100(%rbp), %rdx
leaq -0xe0(%rbp), %rcx
callq 0x3bc0
jmp 0x6828
leaq -0x100(%rbp), %rdi
callq 0x78d0
leaq -0xe0(%rbp), %rdi
callq 0x29e0
leaq -0xa0(%rbp), %rdi
callq 0x78d0
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x6111
leaq -0xe0(%rbp), %rdi
callq 0x29e0
leaq -0xa0(%rbp), %rdi
callq 0x78d0
jmp 0x6ac9
movq -0x1b8(%rbp), %rax
movslq (%rax), %rax
movq %rax, -0x288(%rbp)
leaq -0x179(%rbp), %rdi
movq %rdi, -0x280(%rbp)
callq 0x7ff0
movq -0x288(%rbp), %rsi
movq -0x280(%rbp), %rdx
leaq -0x178(%rbp), %rdi
callq 0x8010
jmp 0x68b7
leaq -0x179(%rbp), %rdi
callq 0x8080
leaq -0x198(%rbp), %rdi
callq 0x2c00
movl $0x0, -0x19c(%rbp)
movl -0x19c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x6a82
movl $0x0, -0x1a0(%rbp)
movl -0x1a0(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x6977
movslq -0x1a0(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x7fd0
movq %rax, %rdi
leaq -0x178(%rbp), %rsi
callq 0x5440
jmp 0x691e
jmp 0x6920
movl -0x1a0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1a0(%rbp)
jmp 0x68f2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x179(%rbp), %rdi
callq 0x8080
jmp 0x6ac9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x198(%rbp), %rdi
callq 0x29e0
leaq -0x178(%rbp), %rdi
callq 0x80a0
jmp 0x6ac9
movl $0x0, -0x1a4(%rbp)
movl $0x0, -0x1a8(%rbp)
movq -0x1b8(%rbp), %rcx
movl -0x1a8(%rbp), %eax
cmpl (%rcx), %eax
jge 0x69fa
movslq -0x1a8(%rbp), %rsi
leaq -0x178(%rbp), %rdi
callq 0x7c30
movq (%rax), %rax
movq %rax, -0x290(%rbp)
movslq -0x1a4(%rbp), %rsi
leaq -0x178(%rbp), %rdi
callq 0x7c30
movq %rax, %rcx
movq -0x290(%rbp), %rax
cmpq (%rcx), %rax
jle 0x69e7
movl -0x1a8(%rbp), %eax
movl %eax, -0x1a4(%rbp)
jmp 0x69e9
movl -0x1a8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1a8(%rbp)
jmp 0x698b
leaq -0x198(%rbp), %rdi
leaq -0x1a4(%rbp), %rsi
callq 0x7860
jmp 0x6a0f
movl $0x0, -0x1ac(%rbp)
movl -0x1ac(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x6a57
movslq -0x1ac(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x7fd0
movq %rax, %rdi
movl -0x1a4(%rbp), %esi
callq 0x5590
jmp 0x6a44
jmp 0x6a46
movl -0x1ac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1ac(%rbp)
jmp 0x6a19
movq -0x1c8(%rbp), %rdi
leaq -0x1a4(%rbp), %rsi
callq 0x7860
jmp 0x6a6c
jmp 0x6a6e
movl -0x19c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x19c(%rbp)
jmp 0x68d9
movb $0x1, -0x65(%rbp)
leaq -0x198(%rbp), %rdi
callq 0x29e0
leaq -0x178(%rbp), %rdi
callq 0x80a0
testb $0x1, -0x65(%rbp)
jne 0x6ab0
movq -0x1c8(%rbp), %rdi
callq 0x29e0
leaq -0x50(%rbp), %rdi
callq 0x8100
movq -0x1c0(%rbp), %rax
addq $0x290, %rsp            # imm = 0x290
popq %rbp
retq
movq -0x1c8(%rbp), %rdi
callq 0x29e0
leaq -0x50(%rbp), %rdi
callq 0x8100
movq -0x60(%rbp), %rdi
callq 0x2280
nopw (%rax,%rax)