// File: /workspace/github_cpp_makefile_star2_O2/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 $0xc8, %rsp
movq %rsi, 0x80(%rsp)
movslq 0x50(%rdi), %rsi
xorl %r15d, %r15d
cmpq $0x2, %rsi
jl 0xf3ba
movq %rdi, %r14
leaq 0xa0(%rsp), %r12
leaq 0x60(%rsp), %r13
movq %r12, %rdi
movq %r13, %rdx
callq 0x8852
andq $0x0, 0x10(%r13)
xorps %xmm0, %xmm0
movaps %xmm0, (%r13)
leaq 0x30(%rsp), %rbp
leaq 0x48(%rsp), %rbx
movl %r15d, 0x30(%rsp)
movl 0x50(%r14), %eax
cmpl %eax, %r15d
jge 0xf0f0
movslq %r15d, %rax
movq 0x38(%r14), %rcx
imulq $0x18, %rax, %rdx
movq 0x8(%rcx,%rdx), %rsi
cmpq (%rcx,%rdx), %rsi
je 0xf0ad
movq 0xa0(%rsp), %rcx
cmpl $0x0, (%rcx,%rax,4)
jne 0xf0e3
movq %rbx, %rdi
movq %r14, %rsi
movl %r15d, %edx
movq %r12, %rcx
callq 0xebd1
movq 0x48(%rsp), %rdx
movq 0x50(%rsp), %rcx
movq 0xa0(%rsp), %rax
movq %rdx, %rsi
cmpq %rcx, %rsi
je 0xf0ce
movslq (%rsi), %rdi
cmpl $0x0, (%rax,%rdi,4)
jne 0xf3ee
movl $0x1, (%rax,%rdi,4)
addq $0x4, %rsi
jmp 0xf08e
movq %r13, %rdi
movq %rbp, %rsi
callq 0x6402
movslq 0x30(%rsp), %rax
movq 0xa0(%rsp), %rcx
movl $0x1, (%rcx,%rax,4)
jmp 0xf0e3
movq 0x68(%rsp), %rsi
movq %r13, %rdi
callq 0x107ac
movq %rbx, %rdi
callq 0x38e4
movl 0x30(%rsp), %r15d
incl %r15d
jmp 0xf032
movq 0x60(%rsp), %rcx
movq 0x68(%rsp), %rdx
subq %rcx, %rdx
shrq $0x2, %rdx
cmpl %edx, %eax
jne 0xf42c
xorl %edx, %edx
testl %eax, %eax
cmovlel %edx, %eax
leaq 0x4534c9(%rip), %r15    # 0x4625e0
cmpq %rdx, %rax
je 0xf129
movslq (%rcx,%rdx,4), %rsi
movl %edx, (%r15,%rsi,4)
incq %rdx
jmp 0xf117
movslq 0x50(%r14), %rsi
leaq 0x48(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x8852
movq 0x60(%rsp), %rax
movq 0x38(%r14), %rcx
xorl %edx, %edx
movslq 0x50(%r14), %rsi
cmpq %rsi, %rdx
jge 0xf186
movslq (%rax,%rdx,4), %rsi
imulq $0x18, %rsi, %r8
movq (%rcx,%r8), %rdi
movq 0x8(%rcx,%r8), %r8
movq 0x48(%rsp), %r9
cmpq %r8, %rdi
je 0xf181
movslq (%rdi), %r10
movslq (%r15,%r10,4), %r10
cmpq %r10, %rdx
jge 0xf17b
incl (%r9,%rsi,4)
addq $0x4, %rdi
jmp 0xf166
incq %rdx
jmp 0xf147
leaq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x8852
xorl %r13d, %r13d
fldl 0x11b12(%rip)           # 0x20cb0
fstpt 0xbc(%rsp)
leaq 0x10(%rsp), %rbp
movq $0x0, (%rsp)
movq %r14, 0x88(%rsp)
movslq 0x50(%r14), %rax
cmpq %rax, %r13
jge 0xf38b
movq 0x60(%rsp), %rcx
movslq (%rcx,%r13,4), %r12
testq %r12, %r12
js 0xf40d
cmpl %eax, %r12d
jge 0xf40d
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
andq $0x0, 0x20(%rsp)
movq 0x38(%r14), %rax
imulq $0x18, %r12, %rcx
movq (%rax,%rcx), %rbx
movq 0x8(%rax,%rcx), %r14
cmpq %r14, %rbx
je 0xf229
movslq (%rbx), %rax
movl %eax, 0xc(%rsp)
movslq (%r15,%rax,4), %rax
cmpq %rax, %r13
jge 0xf223
movq %rbp, %rdi
leaq 0xc(%rsp), %rsi
callq 0x6402
addq $0x4, %rbx
jmp 0xf201
movq 0x10(%rsp), %rbp
movq 0x18(%rsp), %rbx
cmpq %rbx, %rbp
je 0xf290
movq %rbx, %r14
subq %rbp, %r14
movq %r14, %rax
sarq $0x2, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x10480
cmpq $0x41, %r14
jl 0xf285
leaq 0x40(%rbp), %r14
movq %rbp, %rdi
movq %r14, %rsi
callq 0x10688
cmpq %rbx, %r14
je 0xf290
movq %r14, %rdi
callq 0x106ff
addq $0x4, %r14
jmp 0xf272
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x10688
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
movq %rcx, %rdx
subq %rax, %rdx
shrq $0x2, %rdx
movq 0x48(%rsp), %rsi
movq 0x30(%rsp), %rdi
testl %edx, %edx
movl $0x0, %r8d
cmovgl %edx, %r8d
decl %edx
xorl %r9d, %r9d
movq 0x88(%rsp), %r14
leaq 0x10(%rsp), %rbp
cmpq %r9, %r8
je 0xf2f3
movslq (%rax,%r9,4), %r10
movl (%rsi,%r10,4), %r11d
cmpl %edx, %r11d
jl 0xf3cf
jne 0xf2ec
movl $0x1, (%rdi,%r10,4)
incq %r9
decl %edx
jmp 0xf2cc
movq 0x30(%rsp), %rdx
cmpl $0x0, (%rdx,%r12,4)
jne 0xf37b
movq 0x80(%rsp), %rdx
movq (%rdx), %rsi
movq (%rsi,%r12,8), %rdx
cmpq %rcx, %rax
je 0xf353
movslq (%rax), %rdi
movq %rdx, 0x90(%rsp)
fildll 0x90(%rsp)
movq (%rsi,%rdi,8), %rdi
movq %rdi, 0x98(%rsp)
fildll 0x98(%rsp)
fmulp %st, %st(1)
fldt 0xbc(%rsp)
fxch %st(1)
fucompi %st(1), %st
fstp %st(0)
ja 0xf35f
imulq %rdi, %rdx
addq $0x4, %rax
jmp 0xf30e
movabsq $0xde0b6b3a7640000, %rax # imm = 0xDE0B6B3A7640000
jmp 0xf36c
movabsq $0xde0b6b3a7640000, %rax # imm = 0xDE0B6B3A7640000
movq %rax, %rdx
addq (%rsp), %rdx
cmpq %rax, %rdx
cmovgeq %rax, %rdx
movq %rdx, (%rsp)
movq %rbp, %rdi
callq 0x38e4
incq %r13
jmp 0xf1ba
leaq 0x30(%rsp), %rdi
callq 0x38e4
leaq 0x48(%rsp), %rdi
callq 0x38e4
leaq 0x60(%rsp), %rdi
callq 0x38e4
leaq 0xa0(%rsp), %rdi
callq 0x38e4
movq (%rsp), %r15
movq %r15, %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x11adf(%rip), %rdi     # 0x20eb5
leaq 0x11902(%rip), %rsi     # 0x20cdf
leaq 0x11a8e(%rip), %rcx     # 0x20e72
movl $0x11a, %edx            # imm = 0x11A
callq 0x2150
leaq 0x11a29(%rip), %rdi     # 0x20e1e
leaq 0x118e3(%rip), %rsi     # 0x20cdf
leaq 0x11a6f(%rip), %rcx     # 0x20e72
movl $0xf7, %edx
callq 0x2150
leaq 0x11a52(%rip), %rdi     # 0x20e66
leaq 0x118c4(%rip), %rsi     # 0x20cdf
leaq 0x11a50(%rip), %rcx     # 0x20e72
movl $0x10e, %edx            # imm = 0x10E
callq 0x2150
leaq 0x11a1a(%rip), %rdi     # 0x20e4d
leaq 0x118a5(%rip), %rsi     # 0x20cdf
leaq 0x11a31(%rip), %rcx     # 0x20e72
movl $0xfd, %edx
callq 0x2150
jmp 0xf44f
jmp 0xf456
movq %rax, %rbx
jmp 0xf472
jmp 0xf456
movq %rax, %rbx
jmp 0xf47c
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x38e4
leaq 0x30(%rsp), %rdi
callq 0x38e4
leaq 0x48(%rsp), %rdi
callq 0x38e4
leaq 0x60(%rsp), %rdi
callq 0x38e4
leaq 0xa0(%rsp), %rdi
callq 0x38e4
movq %rbx, %rdi
callq 0x2340