// File: 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
movq %rsp, %rbp
subq $0x250, %rsp            # imm = 0x250
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x1, 0x50(%rax)
jg 0x2a2ca
movq $0x0, -0x8(%rbp)
jmp 0x2ac82
movq -0x10(%rbp), %rax
movslq 0x50(%rax), %rax
movq %rax, -0x1e0(%rbp)
leaq -0x31(%rbp), %rdi
movq %rdi, -0x1d8(%rbp)
callq 0x111b0
movq -0x1e0(%rbp), %rsi
movq -0x1d8(%rbp), %rdx
leaq -0x30(%rbp), %rdi
callq 0x17ab0
jmp 0x2a302
leaq -0x31(%rbp), %rdi
callq 0x6620
leaq -0x60(%rbp), %rdi
callq 0xdf40
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x50(%rcx), %eax
jge 0x2a546
movq -0x10(%rbp), %rdi
addq $0x38, %rdi
movslq -0x64(%rbp), %rsi
callq 0xbba0
movq %rax, %rdi
callq 0x59a0
cmpq $0x0, %rax
jne 0x2a39c
leaq -0x60(%rbp), %rdi
leaq -0x64(%rbp), %rsi
callq 0xdff0
jmp 0x2a359
movslq -0x64(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0x178f0
movl $0x1, (%rax)
jmp 0x2a536
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x31(%rbp), %rdi
callq 0x6620
jmp 0x2ac8f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2ac6e
movslq -0x64(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0x178f0
cmpl $0x0, (%rax)
jne 0x2a534
movq -0x10(%rbp), %rsi
movl -0x64(%rbp), %edx
leaq -0x80(%rbp), %rdi
leaq -0x30(%rbp), %rcx
callq 0x29a80
jmp 0x2a3c8
leaq -0x80(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rdi
callq 0xe060
movq %rax, -0x90(%rbp)
movq -0x88(%rbp), %rdi
callq 0xe090
movq %rax, -0x98(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0xe0c0
testb $0x1, %al
jne 0x2a412
jmp 0x2a483
leaq -0x90(%rbp), %rdi
callq 0xe100
movl (%rax), %eax
movl %eax, -0x9c(%rbp)
movslq -0x9c(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0x178f0
cmpl $0x0, (%rax)
jne 0x2a43d
jmp 0x2a45c
leaq 0x2f9aa(%rip), %rdi     # 0x59dee
leaq 0x2f864(%rip), %rsi     # 0x59caf
movl $0xf7, %edx
leaq 0x2f9eb(%rip), %rcx     # 0x59e42
callq 0x31a0
movslq -0x9c(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0x178f0
movl $0x1, (%rax)
leaq -0x90(%rbp), %rdi
callq 0xe120
jmp 0x2a3f9
leaq -0x60(%rbp), %rdi
movq %rdi, -0x1f0(%rbp)
callq 0xe090
movq %rax, -0xb0(%rbp)
leaq -0xa8(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x177f0
leaq -0x80(%rbp), %rdi
movq %rdi, -0x1f8(%rbp)
callq 0xe060
movq -0x1f8(%rbp), %rdi
movq %rax, -0xb8(%rbp)
callq 0xe090
movq -0x1f0(%rbp), %rdi
movq %rax, -0xc0(%rbp)
movq -0xa8(%rbp), %rsi
movq -0xb8(%rbp), %rdx
movq -0xc0(%rbp), %rcx
callq 0x2de00
movq %rax, -0x1e8(%rbp)
jmp 0x2a501
movq -0x1e8(%rbp), %rax
movq %rax, -0xc8(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x6d30
jmp 0x2a534
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x6d30
jmp 0x2ac6e
jmp 0x2a536
jmp 0x2a538
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x2a31b
leaq -0x60(%rbp), %rdi
callq 0x59a0
movq -0x10(%rbp), %rcx
cmpl 0x50(%rcx), %eax
jne 0x2a55a
jmp 0x2a579
leaq 0x2f8bc(%rip), %rdi     # 0x59e1d
leaq 0x2f747(%rip), %rsi     # 0x59caf
movl $0xfd, %edx
leaq 0x2f8ce(%rip), %rcx     # 0x59e42
callq 0x31a0
movl $0x0, -0xcc(%rbp)
movl -0xcc(%rbp), %eax
movl %eax, -0x1fc(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x59a0
movq %rax, %rcx
movl -0x1fc(%rbp), %eax
cmpl %ecx, %eax
jge 0x2a5e5
movl -0xcc(%rbp), %eax
movl %eax, -0x200(%rbp)
movslq -0xcc(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x178f0
movl -0x200(%rbp), %edx
movslq (%rax), %rcx
leaq 0x4820df(%rip), %rax    # 0x4ac6b0
movl %edx, (%rax,%rcx,4)
movl -0xcc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xcc(%rbp)
jmp 0x2a583
movq -0x10(%rbp), %rax
movslq 0x50(%rax), %rax
movq %rax, -0x210(%rbp)
leaq -0xe9(%rbp), %rdi
movq %rdi, -0x208(%rbp)
callq 0x111b0
movq -0x210(%rbp), %rsi
movq -0x208(%rbp), %rdx
leaq -0xe8(%rbp), %rdi
callq 0x17ab0
jmp 0x2a623
leaq -0xe9(%rbp), %rdi
callq 0x6620
movl $0x0, -0xf0(%rbp)
movl -0xf0(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x50(%rcx), %eax
jge 0x2a74d
movslq -0xf0(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x178f0
movl (%rax), %eax
movl %eax, -0xf4(%rbp)
movq -0x10(%rbp), %rdi
addq $0x38, %rdi
movslq -0xf4(%rbp), %rsi
callq 0xbba0
movq %rax, -0x100(%rbp)
movq -0x100(%rbp), %rdi
callq 0x6680
movq %rax, -0x108(%rbp)
movq -0x100(%rbp), %rdi
callq 0x66b0
movq %rax, -0x110(%rbp)
leaq -0x108(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0xbbc0
testb $0x1, %al
jne 0x2a6be
jmp 0x2a737
leaq -0x108(%rbp), %rdi
callq 0xbc00
movl (%rax), %eax
movl %eax, -0x114(%rbp)
movslq -0x114(%rbp), %rcx
leaq 0x481fd0(%rip), %rax    # 0x4ac6b0
movl (%rax,%rcx,4), %eax
cmpl -0xf0(%rbp), %eax
jle 0x2a724
movslq -0xf4(%rbp), %rsi
leaq -0xe8(%rbp), %rdi
callq 0x178f0
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x2a724
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xe9(%rbp), %rdi
callq 0x6620
jmp 0x2ac6e
jmp 0x2a726
leaq -0x108(%rbp), %rdi
callq 0xbc80
jmp 0x2a6a5
jmp 0x2a739
movl -0xf0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf0(%rbp)
jmp 0x2a639
movq -0x10(%rbp), %rax
movslq 0x50(%rax), %rax
movq %rax, -0x220(%rbp)
leaq -0x131(%rbp), %rdi
movq %rdi, -0x218(%rbp)
callq 0x111b0
movq -0x220(%rbp), %rsi
movq -0x218(%rbp), %rdx
leaq -0x130(%rbp), %rdi
callq 0x17ab0
jmp 0x2a78b
leaq -0x131(%rbp), %rdi
callq 0x6620
movq $0x0, -0x140(%rbp)
movl $0x0, -0x144(%rbp)
movl -0x144(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x50(%rcx), %eax
jge 0x2ac2b
movslq -0x144(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x178f0
movl (%rax), %eax
movl %eax, -0x148(%rbp)
xorl %eax, %eax
xorl %ecx, %ecx
cmpl -0x148(%rbp), %ecx
movb %al, -0x221(%rbp)
jg 0x2a7ff
movl -0x148(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x50(%rcx), %eax
setl %al
movb %al, -0x221(%rbp)
movb -0x221(%rbp), %al
testb $0x1, %al
jne 0x2a80b
jmp 0x2a80d
jmp 0x2a849
leaq 0x2f622(%rip), %rdi     # 0x59e36
leaq 0x2f494(%rip), %rsi     # 0x59caf
movl $0x10e, %edx            # imm = 0x10E
leaq 0x2f61b(%rip), %rcx     # 0x59e42
callq 0x31a0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x131(%rbp), %rdi
callq 0x6620
jmp 0x2ac62
leaq -0x160(%rbp), %rdi
callq 0xdf40
movq -0x10(%rbp), %rdi
addq $0x38, %rdi
movslq -0x148(%rbp), %rsi
callq 0xbba0
movq %rax, -0x168(%rbp)
movq -0x168(%rbp), %rdi
callq 0x6680
movq %rax, -0x170(%rbp)
movq -0x168(%rbp), %rdi
callq 0x66b0
movq %rax, -0x178(%rbp)
leaq -0x170(%rbp), %rdi
leaq -0x178(%rbp), %rsi
callq 0xbbc0
testb $0x1, %al
jne 0x2a8b2
jmp 0x2a932
leaq -0x170(%rbp), %rdi
callq 0xbc00
movl (%rax), %eax
movl %eax, -0x17c(%rbp)
movslq -0x17c(%rbp), %rcx
leaq 0x481ddc(%rip), %rax    # 0x4ac6b0
movl (%rax,%rcx,4), %eax
cmpl -0x144(%rbp), %eax
jle 0x2a91f
leaq -0x160(%rbp), %rdi
leaq -0x17c(%rbp), %rsi
callq 0xdff0
jmp 0x2a8f4
jmp 0x2a91f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x6d30
leaq -0x130(%rbp), %rdi
callq 0x6d30
jmp 0x2ac62
jmp 0x2a921
leaq -0x170(%rbp), %rdi
callq 0xbc80
jmp 0x2a896
leaq -0x160(%rbp), %rdi
movq %rdi, -0x230(%rbp)
callq 0xe060
movq -0x230(%rbp), %rdi
movq %rax, -0x188(%rbp)
callq 0xe090
movq %rax, -0x190(%rbp)
movq -0x188(%rbp), %rdi
movq -0x190(%rbp), %rsi
callq 0x2aca0
jmp 0x2a974
movl $0x0, -0x198(%rbp)
movl -0x198(%rbp), %eax
movl %eax, -0x234(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x59a0
movq %rax, %rcx
movl -0x234(%rbp), %eax
cmpl %ecx, %eax
jge 0x2aa9e
movslq -0x198(%rbp), %rsi
leaq -0x160(%rbp), %rdi
callq 0x178f0
movslq (%rax), %rsi
leaq -0xe8(%rbp), %rdi
callq 0x178f0
movl (%rax), %eax
movl %eax, -0x238(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x59a0
movq %rax, %rcx
movl -0x238(%rbp), %eax
subl -0x198(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jl 0x2a9f5
jmp 0x2aa14
leaq 0x2f489(%rip), %rdi     # 0x59e85
leaq 0x2f2ac(%rip), %rsi     # 0x59caf
movl $0x11a, %edx            # imm = 0x11A
leaq 0x2f433(%rip), %rcx     # 0x59e42
callq 0x31a0
movslq -0x198(%rbp), %rsi
leaq -0x160(%rbp), %rdi
callq 0x178f0
movslq (%rax), %rsi
leaq -0xe8(%rbp), %rdi
callq 0x178f0
movl (%rax), %eax
movl %eax, -0x23c(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x59a0
movq %rax, %rcx
movl -0x23c(%rbp), %eax
subl -0x198(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x2aa88
movslq -0x198(%rbp), %rsi
leaq -0x160(%rbp), %rdi
callq 0x178f0
movslq (%rax), %rsi
leaq -0x130(%rbp), %rdi
callq 0x178f0
movl $0x1, (%rax)
jmp 0x2aa8a
movl -0x198(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x198(%rbp)
jmp 0x2a97e
movslq -0x148(%rbp), %rsi
leaq -0x130(%rbp), %rdi
callq 0x178f0
cmpl $0x0, (%rax)
jne 0x2ac0b
movq -0x18(%rbp), %rdi
movslq -0x148(%rbp), %rsi
callq 0x12de0
movq (%rax), %rax
movq %rax, -0x1a0(%rbp)
leaq -0x160(%rbp), %rax
movq %rax, -0x1a8(%rbp)
movq -0x1a8(%rbp), %rdi
callq 0xe060
movq %rax, -0x1b0(%rbp)
movq -0x1a8(%rbp), %rdi
callq 0xe090
movq %rax, -0x1b8(%rbp)
leaq -0x1b0(%rbp), %rdi
leaq -0x1b8(%rbp), %rsi
callq 0xe0c0
testb $0x1, %al
jne 0x2ab24
jmp 0x2abd0
leaq -0x1b0(%rbp), %rdi
callq 0xe100
movl (%rax), %eax
movl %eax, -0x1bc(%rbp)
movq -0x1a0(%rbp), %rax
movq %rax, -0x1d0(%rbp)
fildll -0x1d0(%rbp)
fstpt -0x248(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x1bc(%rbp), %rsi
callq 0x12de0
fldt -0x248(%rbp)
movq (%rax), %rax
movq %rax, -0x1c8(%rbp)
fildll -0x1c8(%rbp)
fmulp %st, %st(1)
fldl 0x2f100(%rip)           # 0x59c80
fxch %st(1)
fucompi %st(1), %st
fstp %st(0)
jbe 0x2ab9d
jmp 0x2ab8a
movabsq $0xde0b6b3a7640000, %rax # imm = 0xDE0B6B3A7640000
movq %rax, -0x1a0(%rbp)
jmp 0x2abd0
movq -0x18(%rbp), %rdi
movslq -0x1bc(%rbp), %rsi
callq 0x12de0
movq (%rax), %rax
imulq -0x1a0(%rbp), %rax
movq %rax, -0x1a0(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0xe120
jmp 0x2ab08
movq -0x1a0(%rbp), %rax
addq -0x140(%rbp), %rax
movq %rax, -0x140(%rbp)
movabsq $0xde0b6b3a7640000, %rax # imm = 0xDE0B6B3A7640000
cmpq %rax, -0x140(%rbp)
jle 0x2ac09
movabsq $0xde0b6b3a7640000, %rax # imm = 0xDE0B6B3A7640000
movq %rax, -0x140(%rbp)
jmp 0x2ac0b
leaq -0x160(%rbp), %rdi
callq 0x6d30
movl -0x144(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x144(%rbp)
jmp 0x2a7ac
movq -0x140(%rbp), %rax
movq %rax, -0x8(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x6d30
leaq -0xe8(%rbp), %rdi
callq 0x6d30
leaq -0x60(%rbp), %rdi
callq 0x6d30
leaq -0x30(%rbp), %rdi
callq 0x6d30
jmp 0x2ac82
leaq -0xe8(%rbp), %rdi
callq 0x6d30
leaq -0x60(%rbp), %rdi
callq 0x6d30
leaq -0x30(%rbp), %rdi
callq 0x6d30
jmp 0x2ac8f
movq -0x8(%rbp), %rax
addq $0x250, %rsp            # imm = 0x250
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x3480
nopl (%rax,%rax)