// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movl %r8d, %ebx
movl %ecx, 0x70(%rsp)
movq %rsi, %r15
movq %rdi, 0x20(%rsp)
andl $0x0, (%rsi)
movq (%rdx), %rdi
movq %rdx, 0x90(%rsp)
movq 0x8(%rdx), %rsi
movq %rsi, %rax
subq %rdi, %rax
shrq $0x4, %rax
movl %eax, 0x4(%r15)
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
shlq $0x4, %rax
xorl %edx, %edx
cmpq %rcx, %rax
je 0x3687
movl (%rdi,%rcx), %r8d
movl 0x4(%rdi,%rcx), %r9d
cmpl %r9d, %r8d
cmovgl %r8d, %r9d
incl %r9d
cmpl %r9d, %edx
cmovlel %r9d, %edx
movl %edx, (%r15)
addq $0x10, %rcx
jmp 0x365f
callq 0x5af9
leaq 0x8(%r15), %r12
movslq 0x4(%r15), %rsi
movq %r12, %rdi
callq 0x3f38
leaq 0x38(%r15), %rdi
movslq 0x4(%r15), %rsi
movq %rdi, 0x88(%rsp)
callq 0x3f38
leaq 0x20(%r15), %rbp
movslq (%r15), %rsi
incq %rsi
movq %rbp, %rdi
callq 0x3f38
leaq 0x50(%r15), %rdi
movslq (%r15), %rsi
incq %rsi
movq %rdi, 0x68(%rsp)
callq 0x3f38
movslq %ebx, %rbx
leaq 0xa0(%rsp), %rdi
movq %rsp, %r14
movq %rbx, %rsi
movq %r14, %rdx
callq 0x4130
movq 0x20(%rsp), %rax
andq $0x0, 0x10(%rax)
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
xorl %eax, %eax
testl %ebx, %ebx
cmovlel %eax, %ebx
movq %rbx, 0x78(%rsp)
leaq 0x50(%rsp), %rbx
xorl %esi, %esi
movq %r15, 0x28(%rsp)
cmpq 0x78(%rsp), %rsi
je 0x399c
leaq 0xb8(%rsp), %rdi
movq %rsi, 0x80(%rsp)
callq 0x4182
movslq (%r15), %rsi
incq %rsi
andl $0x0, (%rsp)
movq %rbp, %rdi
movq %r14, %rdx
callq 0x646a
movslq (%r15), %rsi
incq %rsi
andl $0x0, (%rsp)
movq 0x68(%rsp), %rdi
movq %r14, %rdx
callq 0x646a
andq $0x0, 0x10(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, (%rsp)
xorl %r14d, %r14d
xorl %r15d, %r15d
xorl %r13d, %r13d
movq 0x28(%rsp), %rax
movslq 0x4(%rax), %rax
cmpq %rax, %r15
jge 0x37fa
leaq 0xb8(%rsp), %rdi
callq 0x41ce
movq 0x90(%rsp), %rax
movq (%rax), %rax
movsd 0x8(%rax,%r14), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x37f1
movl 0x4(%rax,%r14), %ecx
movslq %r13d, %rdx
movq (%r12), %rsi
movl %ecx, (%rsi,%rdx,4)
movslq (%rax,%r14), %rcx
movq (%rbp), %rdx
incl 0x4(%rdx,%rcx,4)
movl (%rax,%r14), %ecx
movl 0x4(%rax,%r14), %eax
shlq $0x20, %rcx
orq %rax, %rcx
movq %rcx, 0x30(%rsp)
movq %rsp, %rdi
leaq 0x30(%rsp), %rsi
callq 0x4e24
incl %r13d
incq %r15
addq $0x10, %r14
jmp 0x377e
movq (%rbp), %rax
andl $0x0, (%rax)
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x4fa1
movq (%rsp), %rax
movq 0x88(%rsp), %rcx
movq (%rcx), %rcx
movq 0x68(%rsp), %rdx
movq (%rdx), %rdx
testl %r13d, %r13d
movl $0x0, %esi
cmovlel %esi, %r13d
xorl %esi, %esi
leaq 0x30(%rsp), %r14
movq 0x28(%rsp), %r15
cmpq %rsi, %r13
je 0x385c
movl 0x4(%rax,%rsi,8), %edi
movl %edi, (%rcx,%rsi,4)
movslq (%rax,%rsi,8), %rdi
incl 0x4(%rdx,%rdi,4)
leaq 0x30(%rsp), %r14
incq %rsi
jmp 0x383e
movq (%rbp), %rax
movq 0x68(%rsp), %rcx
movq (%rcx), %rcx
pushq $0x1
popq %rdx
movslq (%r15), %rsi
cmpq %rsi, %rdx
jg 0x3886
movl -0x4(%rax,%rdx,4), %esi
addl %esi, (%rax,%rdx,4)
movl -0x4(%rcx,%rdx,4), %esi
addl %esi, (%rcx,%rdx,4)
incq %rdx
jmp 0x386b
movq %r14, %rdi
movq %rbx, %rdx
callq 0x3eb2
movq %r15, %rdi
movq %r14, %rsi
callq 0x3b36
movl %eax, 0x74(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x50(%rsp)
andq $0x0, 0x60(%rsp)
xorl %r14d, %r14d
movslq (%r15), %rax
cmpq %rax, %r14
jge 0x391c
movq 0x30(%rsp), %rax
movl (%rax,%r14,4), %r15d
movq (%rbp), %rax
movslq (%rax,%r14,4), %r13
incq %r14
movslq (%rax,%r14,4), %rcx
cmpq %rcx, %r13
jge 0x3915
movq (%r12), %rcx
movslq (%rcx,%r13,4), %rcx
movq 0x30(%rsp), %rdx
movl (%rdx,%rcx,4), %ecx
cmpl %ecx, %r15d
je 0x3910
shlq $0x20, %rcx
orq %r15, %rcx
movq %rcx, 0x98(%rsp)
movq %rbx, %rdi
leaq 0x98(%rsp), %rsi
callq 0x4e24
movq (%rbp), %rax
incq %r13
jmp 0x38cf
movq 0x28(%rsp), %r15
jmp 0x38b3
movq 0x50(%rsp), %rdi
movq 0x58(%rsp), %rsi
callq 0x4fa1
movq %rsp, %r14
movq 0x50(%rsp), %rdi
movq 0x58(%rsp), %rsi
callq 0x656e
movq 0x58(%rsp), %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x420c
imulq $0x1d0, 0x80(%rsp), %rdi # imm = 0x1D0
addq 0xa0(%rsp), %rdi
movl 0x74(%rsp), %esi
movq %rbx, %rdx
leaq 0x30(%rsp), %rcx
callq 0x2880
movq %rbx, %rdi
callq 0x4df0
leaq 0x30(%rsp), %rdi
callq 0x284a
movq %r14, %rdi
callq 0x4df0
movq 0x80(%rsp), %rsi
incq %rsi
jmp 0x371a
movslq (%r15), %rsi
movq %rsp, %rdi
leaq 0x30(%rsp), %rdx
callq 0x4212
xorpd %xmm0, %xmm0
leaq 0x30(%rsp), %rax
andq $0x0, 0x10(%rax)
xorl %r13d, %r13d
movl 0x70(%rsp), %ebx
testl %ebx, %ebx
cmovlel %r13d, %ebx
movapd %xmm0, (%rax)
imulq $0x1d0, 0x78(%rsp), %rbp # imm = 0x1D0
leaq 0x50(%rsp), %r15
movq %rsp, %r12
cmpl %ebx, %r13d
je 0x3a86
xorl %r14d, %r14d
cmpq %r14, %rbp
je 0x3a09
movq 0xa0(%rsp), %rdi
addq %r14, %rdi
movq %r12, %rsi
callq 0x317c
addq $0x1d0, %r14            # imm = 0x1D0
jmp 0x39e8
andl $0x0, 0x50(%rsp)
movq 0x28(%rsp), %rax
movl (%rax), %eax
movq (%rsp), %rcx
xorl %edx, %edx
testl %eax, %eax
cmovlel %edx, %eax
xorl %esi, %esi
cmpq %rdx, %rax
je 0x3a3f
movq (%rcx,%rdx,8), %rdi
movslq %esi, %r8
cmpq (%rcx,%r8,8), %rdi
jle 0x3a3a
movl %edx, 0x50(%rsp)
movl %edx, %esi
incq %rdx
jmp 0x3a22
leaq 0x30(%rsp), %rdi
movq %r15, %rsi
callq 0x4034
xorl %r14d, %r14d
cmpq %r14, %rbp
je 0x3a71
movq 0xa0(%rsp), %rdi
addq %r14, %rdi
movl 0x50(%rsp), %esi
callq 0x3228
addq $0x1d0, %r14            # imm = 0x1D0
jmp 0x3a4f
movq 0x20(%rsp), %rdi
movq %r15, %rsi
callq 0x4034
incl %r13d
jmp 0x39dc
leaq 0x30(%rsp), %rdi
callq 0x284a
movq %rsp, %rdi
callq 0x66a2
leaq 0xa0(%rsp), %rdi
callq 0x4264
movq 0x20(%rsp), %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3acf
jmp 0x3af8
jmp 0x3af8
movq %rax, %rbx
jmp 0x3b05
jmp 0x3af3
jmp 0x3af3
jmp 0x3acf
jmp 0x3acf
movq %rax, %rbx
jmp 0x3b17
jmp 0x3adc
jmp 0x3af8
jmp 0x3af3
jmp 0x3adc
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x284a
movq %rsp, %rdi
callq 0x66a2
jmp 0x3b17
movq %rax, %rbx
jmp 0x3b0f
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x4df0
leaq 0x30(%rsp), %rdi
callq 0x284a
movq %rsp, %rdi
callq 0x4df0
movq 0x20(%rsp), %rdi
callq 0x284a
leaq 0xa0(%rsp), %rdi
callq 0x4264
movq %rbx, %rdi
callq 0x21d0