// File: Laakeri[P]Triangulator/src/bayes.cpp
// Function: Bayes::solve()
void solve() {
	BayesIO io;
	Timer timer;
	timer.start();
	io.readInput(cin);
	assert(io.vars == (int)io.variables.size());
	assert(io.vars == (int)io.tableSizes.size());
	set<pair<int, int> > edges;
	// moralizing
	for (auto e : io.dirEdges) {
		edges.insert(minmax(e.F, e.S));
	}
	for (int i = 0; i < io.vars; i++) {
		vector<int> inc;
		for (int ii = 0; ii < io.vars; ii++) {
			if (i != ii && io.dirEdges.count({ii, i})) {
				inc.push_back(ii);
			}
		}
		for (int a : inc) {
			for (int b : inc) {
				if (a < b) {
					edges.insert({a, b});
				}
			}
		}
	}
	cerr<<"Vars: "<<io.variables.size()<<", Edges: "<<io.dirEdges.size()<<", Moralized edges: "<<edges.size()<<endl;
	Graph G(edges);
	vector<int64_t> tableSizes = G.mapTableInto(io.tableSizes);
	auto sol = SolveGraph::solveGraph(G, 0, 1e18, tableSizes);
	assert(sol.S != FAILSOLUTION);
	G.addEdges(sol.S);
	assert(sol.F == MCS::getBayesWidth(G, tableSizes));
	io.printFill(cout, sol.S);
	cerr<<"Total table size: "<<sol.F<<endl;
	cerr<<"*Fill edges: "<<sol.S.size()<<endl;
	cerr<<"Time "<<timer.getTime().count()<<endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x340, %rsp            # imm = 0x340
leaq -0x80(%rbp), %rdi
callq 0xc180
leaq -0x98(%rbp), %rdi
callq 0x55820
jmp 0x9dd2
leaq -0x98(%rbp), %rdi
callq 0x55870
jmp 0x9de0
movq 0x701f1(%rip), %rsi     # 0x79fd8
leaq -0x80(%rbp), %rdi
callq 0xc1d0
jmp 0x9df2
movl -0x8(%rbp), %eax
movl %eax, -0x274(%rbp)
leaq -0x80(%rbp), %rdi
addq $0x30, %rdi
callq 0xdd70
movq %rax, %rcx
movl -0x274(%rbp), %eax
cmpl %ecx, %eax
jne 0x9e17
jmp 0x9e4d
leaq 0x4f5d5(%rip), %rdi     # 0x593f3
leaq 0x4f457(%rip), %rsi     # 0x5927c
movl $0x136, %edx            # imm = 0x136
leaq 0x4f5e6(%rip), %rcx     # 0x59417
callq 0x31a0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0xa697
movl -0x8(%rbp), %eax
movl %eax, -0x278(%rbp)
leaq -0x80(%rbp), %rdi
addq $0x60, %rdi
callq 0xbb80
movq %rax, %rcx
movl -0x278(%rbp), %eax
cmpl %ecx, %eax
jne 0x9e72
jmp 0x9e91
leaq 0x4f5b2(%rip), %rdi     # 0x5942b
leaq 0x4f3fc(%rip), %rsi     # 0x5927c
movl $0x137, %edx            # imm = 0x137
leaq 0x4f58b(%rip), %rcx     # 0x59417
callq 0x31a0
leaq -0xd8(%rbp), %rdi
callq 0x55b0
leaq -0x80(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rdi
callq 0xdd90
movq %rax, -0xe8(%rbp)
movq -0xe0(%rbp), %rdi
callq 0xddc0
movq %rax, -0xf0(%rbp)
leaq -0xe8(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0xddf0
testb $0x1, %al
jne 0x9eea
jmp 0x9fb8
leaq -0xe8(%rbp), %rdi
callq 0xde20
movq (%rax), %rax
movq %rax, -0xf8(%rbp)
leaq -0xf4(%rbp), %rsi
leaq -0xf8(%rbp), %rdi
callq 0xde90
movq %rdx, -0x288(%rbp)
movq %rax, -0x280(%rbp)
jmp 0x9f23
movq -0x288(%rbp), %rax
movq -0x280(%rbp), %rcx
movq %rcx, -0x110(%rbp)
movq %rax, -0x108(%rbp)
leaq -0x100(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0xdee0
jmp 0x9f54
leaq -0xd8(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0xde40
movb %dl, -0x291(%rbp)
movq %rax, -0x290(%rbp)
jmp 0x9f76
movb -0x291(%rbp), %al
movq -0x290(%rbp), %rcx
movq %rcx, -0x120(%rbp)
movb %al, -0x118(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0xdf10
jmp 0x9ece
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0xa68b
movl $0x0, -0x124(%rbp)
movl -0x124(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0xa233
leaq -0x140(%rbp), %rdi
callq 0xdf40
movl $0x0, -0x144(%rbp)
movl -0x144(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0xa0bf
movl -0x124(%rbp), %ecx
xorl %eax, %eax
cmpl -0x144(%rbp), %ecx
movb %al, -0x292(%rbp)
je 0xa063
leaq -0x80(%rbp), %rax
movq %rax, -0x2a0(%rbp)
leaq -0x14c(%rbp), %rdi
leaq -0x144(%rbp), %rsi
leaq -0x124(%rbp), %rdx
callq 0xdfc0
jmp 0xa033
movq -0x2a0(%rbp), %rdi
leaq -0x14c(%rbp), %rsi
callq 0xdf60
movq %rax, -0x2a8(%rbp)
jmp 0xa04f
movq -0x2a8(%rbp), %rax
cmpq $0x0, %rax
setne %al
movb %al, -0x292(%rbp)
movb -0x292(%rbp), %al
testb $0x1, %al
jne 0xa06f
jmp 0xa0a9
leaq -0x140(%rbp), %rdi
leaq -0x144(%rbp), %rsi
callq 0xdff0
jmp 0xa084
jmp 0xa0a9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x140(%rbp), %rdi
callq 0x6d30
jmp 0xa68b
jmp 0xa0ab
movl -0x144(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x144(%rbp)
jmp 0x9fe7
leaq -0x140(%rbp), %rax
movq %rax, -0x158(%rbp)
movq -0x158(%rbp), %rdi
callq 0xe060
movq %rax, -0x160(%rbp)
movq -0x158(%rbp), %rdi
callq 0xe090
movq %rax, -0x168(%rbp)
leaq -0x160(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0xe0c0
testb $0x1, %al
jne 0xa10f
jmp 0xa213
leaq -0x160(%rbp), %rdi
callq 0xe100
movl (%rax), %eax
movl %eax, -0x16c(%rbp)
leaq -0x140(%rbp), %rax
movq %rax, -0x178(%rbp)
movq -0x178(%rbp), %rdi
callq 0xe060
movq %rax, -0x180(%rbp)
movq -0x178(%rbp), %rdi
callq 0xe090
movq %rax, -0x188(%rbp)
leaq -0x180(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0xe0c0
testb $0x1, %al
jne 0xa173
jmp 0xa200
leaq -0x180(%rbp), %rdi
callq 0xe100
movl (%rax), %eax
movl %eax, -0x18c(%rbp)
movl -0x16c(%rbp), %eax
cmpl -0x18c(%rbp), %eax
jge 0xa1ed
leaq -0x194(%rbp), %rdi
leaq -0x16c(%rbp), %rsi
leaq -0x18c(%rbp), %rdx
callq 0xdfc0
jmp 0xa1b1
leaq -0xd8(%rbp), %rdi
leaq -0x194(%rbp), %rsi
callq 0xde40
movb %dl, -0x2b1(%rbp)
movq %rax, -0x2b0(%rbp)
jmp 0xa1d3
movb -0x2b1(%rbp), %al
movq -0x2b0(%rbp), %rcx
movq %rcx, -0x1a8(%rbp)
movb %al, -0x1a0(%rbp)
jmp 0xa1ef
leaq -0x180(%rbp), %rdi
callq 0xe120
jmp 0xa157
jmp 0xa202
leaq -0x160(%rbp), %rdi
callq 0xe120
jmp 0xa0f3
leaq -0x140(%rbp), %rdi
callq 0x6d30
movl -0x124(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x124(%rbp)
jmp 0x9fc2
movq 0x6fdb6(%rip), %rdi     # 0x79ff0
leaq 0x4f20f(%rip), %rsi     # 0x59450
callq 0x32b0
movq %rax, -0x2c0(%rbp)
jmp 0xa24f
leaq -0x50(%rbp), %rdi
callq 0xdd70
movq -0x2c0(%rbp), %rdi
movq %rax, %rsi
callq 0x3080
movq %rax, -0x2c8(%rbp)
jmp 0xa270
movq -0x2c8(%rbp), %rdi
leaq 0x4f1d9(%rip), %rsi     # 0x59457
callq 0x32b0
movq %rax, -0x2d0(%rbp)
jmp 0xa28c
leaq -0x80(%rbp), %rdi
callq 0xe140
movq -0x2d0(%rbp), %rdi
movq %rax, %rsi
callq 0x3080
movq %rax, -0x2d8(%rbp)
jmp 0xa2ad
movq -0x2d8(%rbp), %rdi
leaq 0x4f1a6(%rip), %rsi     # 0x59461
callq 0x32b0
movq %rax, -0x2e0(%rbp)
jmp 0xa2c9
leaq -0xd8(%rbp), %rdi
callq 0xe140
movq -0x2e0(%rbp), %rdi
movq %rax, %rsi
callq 0x3080
movq %rax, -0x2e8(%rbp)
jmp 0xa2ed
movq -0x2e8(%rbp), %rdi
movq 0x6fcbd(%rip), %rsi     # 0x79fb8
callq 0x3300
jmp 0xa302
leaq -0x200(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x15430
jmp 0xa317
leaq -0x20(%rbp), %rdx
leaq -0x218(%rbp), %rdi
leaq -0x200(%rbp), %rsi
callq 0xbe00
jmp 0xa330
leaq -0x250(%rbp), %rdi
leaq -0x218(%rbp), %rsi
callq 0xb9f0
jmp 0xa345
xorl %eax, %eax
movl %eax, %edx
leaq -0x238(%rbp), %rdi
leaq -0x200(%rbp), %rsi
movabsq $0xde0b6b3a7640000, %rcx # imm = 0xDE0B6B3A7640000
leaq -0x250(%rbp), %r8
callq 0x9390
jmp 0xa36f
leaq -0x250(%rbp), %rdi
callq 0xbae0
leaq -0x230(%rbp), %rdi
leaq 0x6ff3f(%rip), %rsi     # 0x7a2c8
callq 0xe160
movb %al, -0x2e9(%rbp)
jmp 0xa396
movb -0x2e9(%rbp), %al
testb $0x1, %al
jne 0xa3a2
jmp 0xa3a7
jmp 0xa42e
leaq 0x4f0c7(%rip), %rdi     # 0x59475
leaq 0x4eec7(%rip), %rsi     # 0x5927c
movl $0x150, %edx            # imm = 0x150
leaq 0x4f056(%rip), %rcx     # 0x59417
callq 0x31a0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0xa67f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0xa673
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x250(%rbp), %rdi
callq 0xbae0
jmp 0xa673
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0xa667
leaq -0x230(%rbp), %rsi
leaq -0x200(%rbp), %rdi
callq 0x15db0
jmp 0xa443
movq -0x238(%rbp), %rax
movq %rax, -0x300(%rbp)
leaq -0x200(%rbp), %rdi
leaq -0x218(%rbp), %rsi
callq 0x2a2a0
movq %rax, -0x2f8(%rbp)
jmp 0xa46d
movq -0x300(%rbp), %rax
movq -0x2f8(%rbp), %rcx
cmpq %rcx, %rax
jne 0xa482
jmp 0xa4a1
leaq 0x4f002(%rip), %rdi     # 0x5948b
leaq 0x4edec(%rip), %rsi     # 0x5927c
movl $0x152, %edx            # imm = 0x152
leaq 0x4ef7b(%rip), %rcx     # 0x59417
callq 0x31a0
leaq -0x230(%rbp), %rsi
leaq -0x268(%rbp), %rdi
callq 0x56a0
jmp 0xa4b6
movq 0x6fb0b(%rip), %rsi     # 0x79fc8
leaq -0x80(%rbp), %rdi
leaq -0x268(%rbp), %rdx
callq 0xe190
jmp 0xa4cf
leaq -0x268(%rbp), %rdi
callq 0x5470
movq 0x6fb0e(%rip), %rdi     # 0x79ff0
leaq 0x4efcd(%rip), %rsi     # 0x594b6
callq 0x32b0
movq %rax, -0x308(%rbp)
jmp 0xa4f7
movq -0x308(%rbp), %rdi
movq -0x238(%rbp), %rsi
callq 0x34b0
movq %rax, -0x310(%rbp)
jmp 0xa513
movq -0x310(%rbp), %rdi
movq 0x6fa97(%rip), %rsi     # 0x79fb8
callq 0x3300
jmp 0xa528
movq 0x6fac1(%rip), %rdi     # 0x79ff0
leaq 0x4ecc5(%rip), %rsi     # 0x591fb
callq 0x32b0
movq %rax, -0x318(%rbp)
jmp 0xa544
leaq -0x230(%rbp), %rdi
callq 0x5680
movq -0x318(%rbp), %rdi
movq %rax, %rsi
callq 0x3080
movq %rax, -0x320(%rbp)
jmp 0xa568
movq -0x320(%rbp), %rdi
movq 0x6fa42(%rip), %rsi     # 0x79fb8
callq 0x3300
jmp 0xa57d
movq 0x6fa6c(%rip), %rdi     # 0x79ff0
leaq 0x4ef3e(%rip), %rsi     # 0x594c9
callq 0x32b0
movq %rax, -0x328(%rbp)
jmp 0xa599
leaq -0x98(%rbp), %rdi
callq 0x55920
movsd %xmm0, -0x330(%rbp)
jmp 0xa5af
movsd -0x330(%rbp), %xmm0
movsd %xmm0, -0x270(%rbp)
leaq -0x270(%rbp), %rdi
callq 0x57c0
movsd %xmm0, -0x338(%rbp)
jmp 0xa5d5
movsd -0x338(%rbp), %xmm0
movq -0x328(%rbp), %rdi
callq 0x34c0
movq %rax, -0x340(%rbp)
jmp 0xa5f2
movq -0x340(%rbp), %rdi
movq 0x6f9b8(%rip), %rsi     # 0x79fb8
callq 0x3300
jmp 0xa607
leaq -0x238(%rbp), %rdi
callq 0xbf70
leaq -0x218(%rbp), %rdi
callq 0xbae0
leaq -0x200(%rbp), %rdi
callq 0x59e0
leaq -0xd8(%rbp), %rdi
callq 0x5a70
leaq -0x80(%rbp), %rdi
callq 0xe470
addq $0x340, %rsp            # imm = 0x340
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x268(%rbp), %rdi
callq 0x5470
leaq -0x238(%rbp), %rdi
callq 0xbf70
leaq -0x218(%rbp), %rdi
callq 0xbae0
leaq -0x200(%rbp), %rdi
callq 0x59e0
leaq -0xd8(%rbp), %rdi
callq 0x5a70
leaq -0x80(%rbp), %rdi
callq 0xe470
movq -0xa0(%rbp), %rdi
callq 0x3480
nopl (%rax)