// File: /workspace/github_cpp_makefile_star2_O3/Laakeri[P]Triangulator/src/MCS.cpp
// Function: MCS::getBayesWidth(Graph const&, std::vector<long, std::allocator<long>> const&)
int64_t getBayesWidth(const Graph& G, const vector<int64_t>& tableSizes) {
	if (G.n <= 1) return 0;
	vector<int> u(G.n);
	vector<int> order;
	for (int i = 0; i < G.n; i++) {
		if (G.g[i].size() == 0) {
			order.push_back(i);
			u[i] = 1;
		}
		else if (u[i] == 0) {
			auto ord = MCS_L(G, i, u);
			for (int x : ord) {
				assert(u[x] == 0);
				u[x] = 1;
			}
			order.insert(order.end(), ord.begin(), ord.end());
		}
	}
	assert((int)order.size() == G.n);
	for (int i = 0; i < (int)order.size(); i++) {
		invOrd[order[i]] = i;
	}
	vector<int> fw(G.n);
	for (int i = 0; i < G.n; i++) {
		int x = order[i];
		for (int nx : G.g[x]) {
			if (invOrd[nx] > i) {
				fw[x]++;
			}
		}
	}
	vector<int> noMaxi(G.n);
	int64_t bayesWidth = 0;
	for (int i = 0; i < G.n; i++) {
		int x = order[i];
		assert(0<=x&&x<G.n);
		vector<int> nb;
		for (int nx : G.g[x]) {
			if (invOrd[nx] > i) {
				nb.push_back(nx);
			}
		}
		auto cmp = [&](int a, int b) {
			return invOrd[a] < invOrd[b];
		};
		sort(nb.begin(), nb.end(), cmp);
		for (int ii = 0; ii < (int)nb.size(); ii++) {
			assert(fw[nb[ii]] >= (int)nb.size()-ii-1);
			if (fw[nb[ii]] == (int)nb.size()-ii-1) {
				noMaxi[nb[ii]] = 1;
			}
		}
		if (!noMaxi[x]) {
			int64_t ts = tableSizes[x];
			for (int nx : nb) {
				if ((long double)ts*(long double)tableSizes[nx] > (long double)(maxBWidth)) {
					ts = maxBWidth;
					break;
				}
				ts *= tableSizes[nx];
			}
			bayesWidth += ts;
			if (bayesWidth > maxBWidth) bayesWidth = maxBWidth;
		}
	}
	return bayesWidth;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rsi, 0x90(%rsp)
movslq 0x50(%rdi), %rsi
cmpq $0x2, %rsi
jge 0x13ce5
xorl %eax, %eax
jmp 0x14195
movq %rdi, %rax
leaq 0x78(%rsp), %rdi
movq %rax, 0x70(%rsp)
leaq 0x20(%rsp), %rbx
movq %rbx, %rdx
callq 0xaa18
xorps %xmm0, %xmm0
movaps %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
movq 0x70(%rsp), %rbx
movl $0x0, 0x50(%rsp)
movl 0x50(%rbx), %eax
xorl %edx, %edx
testl %eax, %eax
jle 0x13e1e
leaq 0x20(%rsp), %r15
leaq 0x50(%rsp), %r12
leaq 0x38(%rsp), %r13
leaq 0x78(%rsp), %rbp
movslq %edx, %rax
movq 0x38(%rbx), %rcx
leaq (%rax,%rax,2), %rsi
movq 0x8(%rcx,%rsi,8), %rdi
cmpq (%rcx,%rsi,8), %rdi
je 0x13dc8
movq 0x78(%rsp), %rcx
cmpl $0x0, (%rcx,%rax,4)
jne 0x13dfd
movq %r13, %rdi
movq %rbx, %rsi
movq %rbp, %rcx
callq 0x137a2
movq 0x38(%rsp), %rdx
movq 0x40(%rsp), %rcx
cmpq %rcx, %rdx
je 0x13da2
movq 0x78(%rsp), %rax
movq %rdx, %rsi
movslq (%rsi), %rdi
cmpl $0x0, (%rax,%rdi,4)
jne 0x141c6
movl $0x1, (%rax,%rdi,4)
addq $0x4, %rsi
cmpq %rcx, %rsi
jne 0x13d85
movq 0x28(%rsp), %rsi
movq %r15, %rdi
callq 0x15f3c
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x13dfd
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
jmp 0x13dfd
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0x13de1
movl %edx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x28(%rsp)
jmp 0x13dec
movq %r15, %rdi
movq %r12, %rdx
callq 0x92c4
movslq 0x50(%rsp), %rax
movq 0x78(%rsp), %rcx
movl $0x1, (%rcx,%rax,4)
movl 0x50(%rsp), %edx
incl %edx
movl %edx, 0x50(%rsp)
movl 0x50(%rbx), %eax
cmpl %eax, %edx
jl 0x13d3b
movq 0x20(%rsp), %rdx
movq 0x28(%rsp), %rcx
jmp 0x13e20
xorl %ecx, %ecx
subq %rdx, %rcx
shrq $0x2, %rcx
cmpl %ecx, %eax
jne 0x14204
testl %eax, %eax
jle 0x13e50
movl %eax, %eax
xorl %ecx, %ecx
leaq 0x453792(%rip), %rsi    # 0x4675d0
movslq (%rdx,%rcx,4), %rdi
movl %ecx, (%rsi,%rdi,4)
incq %rcx
cmpq %rcx, %rax
jne 0x13e3e
movl 0x50(%rbx), %eax
movslq %eax, %rsi
leaq 0x38(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0xaa18
movslq 0x50(%rbx), %rsi
testq %rsi, %rsi
jle 0x13ec3
movq 0x20(%rsp), %rax
movq 0x38(%rbx), %rcx
xorl %edx, %edx
leaq 0x453753(%rip), %rdi    # 0x4675d0
movl %esi, %r8d
movslq (%rax,%rdx,4), %rsi
leaq (%rsi,%rsi,2), %r10
movq (%rcx,%r10,8), %r9
movq 0x8(%rcx,%r10,8), %r10
cmpq %r10, %r9
je 0x13eb8
movq 0x38(%rsp), %r8
movslq (%r9), %r11
movslq (%rdi,%r11,4), %r11
cmpq %r11, %rdx
jge 0x13eab
incl (%r8,%rsi,4)
addq $0x4, %r9
cmpq %r10, %r9
jne 0x13e9b
movl 0x50(%rbx), %r8d
incq %rdx
movslq %r8d, %rsi
cmpq %rsi, %rdx
jl 0x13e80
leaq 0x50(%rsp), %rdi
movq %rsp, %rdx
callq 0xaa18
movl 0x50(%rbx), %eax
testl %eax, %eax
jle 0x14128
xorl %r12d, %r12d
fldl 0x15dcc(%rip)           # 0x29cb0
fstpt 0xac(%rsp)
leaq 0x4536de(%rip), %r13    # 0x4675d0
movq %rsp, %rbp
movq $0x0, 0x18(%rsp)
movq 0x20(%rsp), %rcx
movslq (%rcx,%r12,4), %r14
testq %r14, %r14
js 0x141e5
cmpl %eax, %r14d
jge 0x141e5
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq 0x38(%rbx), %rax
leaq (%r14,%r14,2), %rcx
movq (%rax,%rcx,8), %rbx
movq 0x8(%rax,%rcx,8), %r15
cmpq %r15, %rbx
je 0x14019
movslq (%rbx), %rax
movl %eax, 0x6c(%rsp)
movslq (%r13,%rax,4), %rcx
cmpq %rcx, %r12
jge 0x13f7a
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x13f6d
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x13f7a
movq %rbp, %rdi
leaq 0x6c(%rsp), %rdx
callq 0x92c4
addq $0x4, %rbx
cmpq %r15, %rbx
jne 0x13f43
movq (%rsp), %rbp
movq 0x8(%rsp), %rbx
cmpq %rbx, %rbp
je 0x1401d
movq %rbx, %r15
subq %rbp, %r15
movq %r15, %rax
sarq $0x2, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x15722
cmpq $0x41, %r15
jl 0x1400e
leaq 0x40(%rbp), %r15
movq %rbp, %rdi
movq %r15, %rsi
callq 0x15978
cmpq %rbx, %r15
je 0x14019
movl (%r15), %eax
movslq %eax, %rcx
movslq -0x4(%r15), %rdx
movl (%r13,%rcx,4), %edi
movq %r15, %rsi
cmpl (%r13,%rdx,4), %edi
jge 0x14006
movq %r15, %rsi
movl %edx, (%rsi)
movslq -0x8(%rsi), %rdx
movl (%r13,%rcx,4), %edi
addq $-0x4, %rsi
cmpl (%r13,%rdx,4), %edi
jl 0x13ff0
movl %eax, (%rsi)
addq $0x4, %r15
jmp 0x13fcf
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x15978
movq (%rsp), %rbp
movq 0x8(%rsp), %rax
movq %rax, %rdi
subq %rbp, %rdi
shrq $0x2, %rdi
movq 0x50(%rsp), %rcx
testl %edi, %edi
movq 0x70(%rsp), %rbx
jle 0x14072
movq 0x38(%rsp), %rdx
movl %edi, %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
decl %edi
xorl %r8d, %r8d
movslq (%rbp,%r8,4), %r9
movl (%rdx,%r9,4), %r10d
cmpl %edi, %r10d
jl 0x141a7
jne 0x14068
movl $0x1, (%rcx,%r9,4)
incq %r8
decl %edi
cmpq %r8, %rsi
jne 0x1404c
cmpl $0x0, (%rcx,%r14,4)
jne 0x140fe
movq 0x90(%rsp), %rcx
movq (%rcx), %rdx
movq (%rdx,%r14,8), %rcx
cmpq %rax, %rbp
je 0x140e3
movq %rbp, %rsi
movslq (%rsi), %rdi
movq %rcx, 0x98(%rsp)
fildll 0x98(%rsp)
movq (%rdx,%rdi,8), %rdi
movq %rdi, 0xa0(%rsp)
fildll 0xa0(%rsp)
fmulp %st, %st(1)
fldt 0xac(%rsp)
fxch %st(1)
fucompi %st(1), %st
fstp %st(0)
ja 0x140d9
imulq %rdi, %rcx
addq $0x4, %rsi
cmpq %rax, %rsi
jne 0x14094
jmp 0x140e3
movabsq $0xde0b6b3a7640000, %rcx # imm = 0xDE0B6B3A7640000
addq 0x18(%rsp), %rcx
movabsq $0xde0b6b3a7640000, %rax # imm = 0xDE0B6B3A7640000
cmpq %rax, %rcx
cmovgeq %rax, %rcx
movq %rcx, 0x18(%rsp)
testq %rbp, %rbp
je 0x14113
movq 0x10(%rsp), %rsi
subq %rbp, %rsi
movq %rbp, %rdi
callq 0x2210
incq %r12
movslq 0x50(%rbx), %rax
cmpq %rax, %r12
movq %rsp, %rbp
jl 0x13efe
jmp 0x14131
movq $0x0, 0x18(%rsp)
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x14148
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x1415f
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x14176
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x14190
movq 0x88(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq 0x18(%rsp), %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x15d07(%rip), %rdi     # 0x29eb5
leaq 0x15b2a(%rip), %rsi     # 0x29cdf
leaq 0x15cb6(%rip), %rcx     # 0x29e72
movl $0x11a, %edx            # imm = 0x11A
callq 0x2140
leaq 0x15c51(%rip), %rdi     # 0x29e1e
leaq 0x15b0b(%rip), %rsi     # 0x29cdf
leaq 0x15c97(%rip), %rcx     # 0x29e72
movl $0xf7, %edx
callq 0x2140
leaq 0x15c7a(%rip), %rdi     # 0x29e66
leaq 0x15aec(%rip), %rsi     # 0x29cdf
leaq 0x15c78(%rip), %rcx     # 0x29e72
movl $0x10e, %edx            # imm = 0x10E
callq 0x2140
leaq 0x15c42(%rip), %rdi     # 0x29e4d
leaq 0x15acd(%rip), %rsi     # 0x29cdf
leaq 0x15c59(%rip), %rcx     # 0x29e72
movl $0xfd, %edx
callq 0x2140
jmp 0x14229
jmp 0x1422e
jmp 0x1422e
movq %rax, %rbx
jmp 0x14263
movq %rax, %rbx
jmp 0x1427a
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x1424c
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x14263
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x1427a
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x14291
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x142ab
movq 0x88(%rsp), %rsi
subq %rdi, %rsi
callq 0x2210
movq %rbx, %rdi
callq 0x2310