// File: /workspace/github_cpp_makefile_star2_O2/Laakeri[P]Triangulator/src/solver.cpp
// Function: main
int main(int argc, char** argv) {
	assert(argc == 1 || argc == 2 || argc == 3);
	int upperBound = -1;
	int problem = -1;
	
	for (int i = 1; i < argc; i++) {
		string s(argv[i]);
		if (s == "-treewidth") {
			problem = PROBLEM_TREEWIDTH;
		}
		else if (s == "-minfill") {
			problem = PROBLEM_MINFILL;
		}
		else if (s == "-bayes") {
			problem = PROBLEM_BAYES;
		}
		else if (s == "-hyper") {
			problem = PROBLEM_HYPER;
		}
		else if (s == "-frachyper") {
			problem = PROBLEM_FRACHYPER;
		}
		else if (s == "-pmcprogress") {
			PMC::setPrintProgress(true);
		}
		else if (s.size() > 3 && s.substr(0, 3) == "-k=") {
			upperBound = 0;
			for (int j = 3; j < (int)s.size(); j++) {
				assert(isdigit(s[j]));
				upperBound *= 10;
				upperBound += (s[j] - '0');
			}
			cerr<<"Upper bound set to "<<upperBound<<endl;
		}
		else {
			cerr<<"invalid arg"<<endl;
			abort();
		}
	}
	if (problem == -1) {
		cerr<<"No problem specified, defaulting to treewidth"<<endl;
		problem = PROBLEM_TREEWIDTH;
	}
	
	if (upperBound != -1 && problem != PROBLEM_MINFILL && problem != PROBLEM_TREEWIDTH) {
		cerr<<"WARNING: UPPER BOUND HAS EFFECT ONLY FOR TREEWIDTH AND MINFILL"<<endl;
	}
	
	if (problem == PROBLEM_BAYES) {
		Bayes::solve();
	}
	else if (problem == PROBLEM_HYPER) {
		Hyper::solve();
	}
	else if (problem == PROBLEM_FRACHYPER) {
		Hyper::solveFrac();
	}
	else {
		Timer timer;
		timer.start();
		set<pair<int, int> > edges;
		IO io;
		int n = io.readInput(cin, edges);
		assert(n <= maxN);
		Graph G(edges);
		
		if (upperBound == -1) {
			upperBound = (int)1e9;
		}
		if (problem == PROBLEM_MINFILL) {
			if (n == 0) return 0;
			vector<pair<int, int> > sol = MinFill::SolveGraph::solveGraph(G, 0, upperBound, 0);
			
			if (sol == FAILSOLUTION) {
				assert(upperBound < (int)1e9);
				cout<<"No fill in with <= "<<upperBound<<" edges"<<endl;
				cerr<<"No fill in with <= "<<upperBound<<" edges"<<endl;
			}
			else {
				// check correctness
				G.addEdges(sol);
				auto fill0 = MCS::MCS_MP(G);
				assert(fill0.F.size() == 0);
				
				sol = G.mapBack(sol);
				
				io.printFill(cout, sol);
				
				cerr<<"Fill edges: "<<sol.size()<<endl;
				cerr<<"*Treewidth: "<<MCS::getTreeWidth(G)<<endl;
				cerr<<"Time: "<<timer.getTime().count()<<endl;
			}
		}
		else if (problem == PROBLEM_TREEWIDTH) {
			pair<int, vector<pair<int, int> > > sol = TreeWidth::SolveGraph::solveGraph(G, 0, 0, upperBound);
			
			if (sol.S == FAILSOLUTION) {
				assert(upperBound < (int)1e9);
				cout<<"Treewidth > "<<upperBound<<endl;
				cerr<<"Treewidth > "<<upperBound<<endl;
			}
			else {
				// check correctness
				G.addEdges(sol.S);
				auto fill0 = MCS::MCS_MP(G);
				assert(fill0.F.size() == 0);
				
				int treeWidth = MCS::getTreeWidth(G);
				
				assert(treeWidth == sol.F);
				
				auto treeDecomposition = MCS::getTreeDecomposition(G);
				treeDecomposition = G.mapBack(treeDecomposition);
				
				for (auto& bag : treeDecomposition.F) {
					assert((int)bag.size()-1 <= treeWidth);
				}
				
				if (G.n > 0) {
					Graph testT(treeDecomposition.S);
					assert(testT.isConnected());
					assert(testT.n == G.n);
					assert(testT.m == G.n - 1);
				}
				
				io.printTreeDecomposition(cout, treeDecomposition);
				
				cerr<<"Treewidth: "<<treeWidth<<endl;
				cerr<<"*Fill edges: "<<sol.S.size()<<endl;
				cerr<<"Time: "<<timer.getTime().count()<<endl;
			}
		}
		else {
			abort();
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x248, %rsp            # imm = 0x248
leal -0x1(%rdi), %eax
cmpl $0x2, %eax
ja 0x331c
movq %rsi, %r14
movl %edi, %r13d
pushq $-0x1
popq %rax
pushq $0x1
popq %r12
leaq 0x38(%rsp), %r15
leaq 0xc0(%rsp), %rdx
movq %rax, %rbp
movl %eax, 0x4(%rsp)
cmpq %r13, %r12
je 0x2ca8
movq (%r14,%r12,8), %rsi
movq %r15, %rdi
movq %rdx, %rbx
callq 0x3580
movq %r15, %rdi
leaq 0x1d4ee(%rip), %rsi     # 0x2004a
callq 0x35bb
testb %al, %al
je 0x2b69
pushq $0x2
jmp 0x2bc3
movq %r15, %rdi
leaq 0x1d4e2(%rip), %rsi     # 0x20055
callq 0x35bb
testb %al, %al
je 0x2b80
pushq $0x1
jmp 0x2bc3
movq %r15, %rdi
leaq 0x1d4d4(%rip), %rsi     # 0x2005e
callq 0x35bb
testb %al, %al
je 0x2b97
pushq $0x3
jmp 0x2bc3
movq %r15, %rdi
leaq 0x1d4c4(%rip), %rsi     # 0x20065
callq 0x35bb
testb %al, %al
je 0x2bae
pushq $0x4
jmp 0x2bc3
movq %r15, %rdi
leaq 0x1d4b4(%rip), %rsi     # 0x2006c
callq 0x35bb
testb %al, %al
je 0x2bd9
pushq $0x6
popq %rax
movl %eax, %ebp
movq %r15, %rdi
callq 0x20d0
incq %r12
movq %rbx, %rdx
jmp 0x2b3a
movq %r15, %rdi
leaq 0x1d494(%rip), %rsi     # 0x20077
callq 0x35bb
testb %al, %al
je 0x2bf6
pushq $0x1
popq %rdi
callq 0x14b50
jmp 0x2bc6
cmpq $0x4, 0x40(%rsp)
jb 0x3335
movq %rbx, %rdi
movq %r15, %rsi
xorl %edx, %edx
pushq $0x3
popq %rcx
callq 0x2240
leaq 0xc0(%rsp), %rdi
leaq 0x1d463(%rip), %rsi     # 0x20084
callq 0x35bb
movb %al, 0x4(%rsp)
leaq 0xc0(%rsp), %rdi
callq 0x20d0
cmpb $0x0, 0x4(%rsp)
je 0x3335
movslq 0x40(%rsp), %rax
movq 0x38(%rsp), %rcx
movl $0x0, 0x4(%rsp)
pushq $0x3
popq %rdx
cmpq %rax, %rdx
jge 0x2c7c
movsbl (%rcx,%rdx), %esi
addl $-0x30, %esi
cmpl $0xa, %esi
jae 0x32ff
imull $0xa, 0x4(%rsp), %edi
addl %edi, %esi
incq %rdx
movl %esi, 0x4(%rsp)
jmp 0x2c57
movq 0x2d36d(%rip), %rdi     # 0x2fff0
leaq 0x1d40c(%rip), %rsi     # 0x20096
callq 0x2210
movq %rax, %rdi
movl 0x4(%rsp), %esi
callq 0x2330
movq %rax, %rdi
callq 0x20e0
jmp 0x2bc6
cmpl $-0x1, %ebp
jne 0x2ccb
movq 0x2d33c(%rip), %rdi     # 0x2fff0
leaq 0x1d3fb(%rip), %rsi     # 0x200b6
callq 0x2210
movq %rax, %rdi
callq 0x20e0
pushq $0x2
popq %rbp
cmpl $-0x1, 0x4(%rsp)
setne %al
leal -0x3(%rbp), %ecx
cmpl $-0x2, %ecx
setb %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x2cfe
movq 0x2d306(%rip), %rdi     # 0x2fff0
leaq 0x1d3f3(%rip), %rsi     # 0x200e4
callq 0x2210
movq %rax, %rdi
callq 0x20e0
cmpl $0x6, %ebp
je 0x2d21
cmpl $0x4, %ebp
je 0x2d17
cmpl $0x3, %ebp
jne 0x2d2b
callq 0x4721
jmp 0x32eb
callq 0xb6d8
jmp 0x32eb
callq 0xbb07
jmp 0x32eb
leaq 0x180(%rsp), %r14
movq %r14, %rdi
callq 0x1e6b4
movq %r14, %rdi
callq 0x1e6c0
leaq 0x158(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq 0x1a0(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x30(%rax)
movq 0x2d24e(%rip), %rsi     # 0x2ffd8
leaq 0x198(%rsp), %rdi
leaq 0x150(%rsp), %rdx
callq 0xcf50
movl %eax, %r14d
cmpl $0xc351, %eax           # imm = 0xC351
jge 0x3355
leaq 0x38(%rsp), %rdi
leaq 0x150(%rsp), %rsi
callq 0x78ec
movl 0x4(%rsp), %eax
cmpl $-0x1, %eax
movl $0x3b9aca00, %r15d      # imm = 0x3B9ACA00
cmovnel %eax, %r15d
cmpl $0x1, %ebp
je 0x2e78
cmpl $0x2, %ebp
jne 0x3350
leaq 0x130(%rsp), %rdi
leaq 0x38(%rsp), %rsi
xorl %edx, %edx
xorl %ecx, %ecx
movl %r15d, %r8d
callq 0x1efed
leaq 0x138(%rsp), %rbx
leaq 0x2d3d6(%rip), %rsi     # 0x301e0
movq %rbx, %rdi
callq 0x35c8
testb %al, %al
je 0x2f2d
cmpl $0x3b9aca00, %r15d      # imm = 0x3B9ACA00
jge 0x336e
movq 0x2d19a(%rip), %rdi     # 0x2ffc8
leaq 0x1d351(%rip), %rsi     # 0x20186
callq 0x2210
movq %rax, %rdi
movl %r15d, %esi
callq 0x2330
movq %rax, %rdi
callq 0x20e0
movq 0x2d19c(%rip), %rdi     # 0x2fff0
leaq 0x1d32b(%rip), %rsi     # 0x20186
callq 0x2210
movq %rax, %rdi
movl %r15d, %esi
callq 0x2330
movq %rax, %rdi
callq 0x20e0
jmp 0x316b
testl %r14d, %r14d
je 0x32c7
leaq 0x8(%rsp), %rdi
leaq 0x38(%rsp), %rsi
xorl %edx, %edx
movl %r15d, %ecx
xorl %r8d, %r8d
callq 0x110b7
leaq 0x2d341(%rip), %rsi     # 0x301e0
leaq 0x8(%rsp), %rdi
callq 0x35c8
testb %al, %al
je 0x3173
cmpl $0x3b9aca00, %r15d      # imm = 0x3B9ACA00
jge 0x33c2
movq 0x2d103(%rip), %rdi     # 0x2ffc8
leaq 0x1d277(%rip), %rsi     # 0x20143
callq 0x2210
movq %rax, %rdi
movl %r15d, %esi
callq 0x2330
leaq 0x1d274(%rip), %rsi     # 0x20157
movq %rax, %rdi
callq 0x2210
movq %rax, %rdi
callq 0x20e0
movq 0x2d0f6(%rip), %rdi     # 0x2fff0
leaq 0x1d242(%rip), %rsi     # 0x20143
callq 0x2210
movq %rax, %rdi
movl %r15d, %esi
callq 0x2330
leaq 0x1d23f(%rip), %rsi     # 0x20157
movq %rax, %rdi
callq 0x2210
movq %rax, %rdi
callq 0x20e0
jmp 0x32bd
leaq 0x38(%rsp), %rdi
movq %rbx, %rsi
callq 0x7cf8
leaq 0x8(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0xe30c
movq 0x10(%rsp), %rax
cmpq 0x8(%rsp), %rax
jne 0x3387
leaq 0x38(%rsp), %rdi
callq 0xed88
movl %eax, %ebp
cmpl 0x130(%rsp), %eax
jne 0x33a3
leaq 0x90(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0xfb1f
leaq 0x218(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x3658
leaq 0xc0(%rsp), %rdi
leaq 0x38(%rsp), %rsi
leaq 0x218(%rsp), %rdx
callq 0x8302
leaq 0x90(%rsp), %r14
leaq 0xc0(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x3692
movq %r15, %rdi
callq 0x36bc
leaq 0x218(%rsp), %rdi
callq 0x36bc
movq (%r14), %rax
movq 0x8(%r14), %rcx
cmpq %rcx, %rax
je 0x3023
movq 0x8(%rax), %rdx
subq (%rax), %rdx
shrq $0x2, %rdx
decl %edx
addq $0x18, %rax
cmpl %ebp, %edx
jle 0x2fea
leaq 0x1d19b(%rip), %rdi     # 0x201a6
leaq 0x1d016(%rip), %rsi     # 0x20028
leaq 0x1d01a(%rip), %rcx     # 0x20033
movl $0x88, %edx
callq 0x2150
cmpl $0x0, 0x88(%rsp)
jle 0x3087
leaq 0xa8(%rsp), %rsi
leaq 0xc0(%rsp), %rdi
callq 0x7b04
leaq 0xc0(%rsp), %rdi
callq 0x83e4
testb %al, %al
je 0x33fa
movl 0x110(%rsp), %eax
cmpl 0x88(%rsp), %eax
jne 0x3419
decl %eax
cmpl %eax, 0x114(%rsp)
jne 0x3438
leaq 0xc0(%rsp), %rdi
callq 0x36d2
leaq 0x1e8(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x3658
movq 0x2cf25(%rip), %rsi     # 0x2ffc8
leaq 0x198(%rsp), %rdi
leaq 0x1e8(%rsp), %rdx
callq 0xd708
leaq 0x1e8(%rsp), %rdi
callq 0x36bc
movq 0x2cf24(%rip), %rdi     # 0x2fff0
leaq 0x1d0a0(%rip), %rsi     # 0x20173
callq 0x2210
movq %rax, %rdi
movl %ebp, %esi
callq 0x2330
movq %rax, %rdi
callq 0x20e0
movq 0x2ceff(%rip), %rdi     # 0x2fff0
leaq 0x1d103(%rip), %rsi     # 0x201fb
callq 0x2210
movq 0x140(%rsp), %rsi
subq 0x138(%rsp), %rsi
sarq $0x3, %rsi
movq %rax, %rdi
callq 0x2160
movq %rax, %rdi
callq 0x20e0
movq 0x2cec8(%rip), %rdi     # 0x2fff0
leaq 0x1d050(%rip), %rsi     # 0x2017f
callq 0x2210
movq %rax, %r14
leaq 0x180(%rsp), %rdi
callq 0x1e706
movq %r14, %rdi
callq 0x2300
movq %rax, %rdi
callq 0x20e0
leaq 0x90(%rsp), %rdi
callq 0x36bc
leaq 0x8(%rsp), %rdi
callq 0x3642
movq %rbx, %rdi
jmp 0x32c2
leaq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x7cf8
leaq 0xc0(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0xe30c
movq 0xc8(%rsp), %rax
cmpq 0xc0(%rsp), %rax
jne 0x33de
leaq 0x118(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x35f2
leaq 0x90(%rsp), %rdi
leaq 0x38(%rsp), %rsi
leaq 0x118(%rsp), %rdx
callq 0x82b2
leaq 0x8(%rsp), %rbx
leaq 0x90(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3d74
movq %r14, %rdi
callq 0x3bfe
leaq 0x118(%rsp), %rdi
callq 0x3bfe
movq 0x2cdbe(%rip), %rsi     # 0x2ffc8
leaq 0x198(%rsp), %rdi
movq %rbx, %rdx
callq 0xd62c
movq 0x2cdcf(%rip), %rdi     # 0x2fff0
leaq 0x1cfd4(%rip), %rsi     # 0x201fc
callq 0x2210
movq 0x10(%rsp), %rsi
subq 0x8(%rsp), %rsi
sarq $0x3, %rsi
movq %rax, %rdi
callq 0x2160
movq %rax, %rdi
callq 0x20e0
movq 0x2cd9e(%rip), %rdi     # 0x2fff0
leaq 0x1cf19(%rip), %rsi     # 0x20172
callq 0x2210
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0xed88
movq %rbx, %rdi
movl %eax, %esi
callq 0x2330
movq %rax, %rdi
callq 0x20e0
movq 0x2cd6c(%rip), %rdi     # 0x2fff0
leaq 0x1cef4(%rip), %rsi     # 0x2017f
callq 0x2210
movq %rax, %rbx
leaq 0x180(%rsp), %rdi
callq 0x1e706
movq %rbx, %rdi
callq 0x2300
movq %rax, %rdi
callq 0x20e0
leaq 0xc0(%rsp), %rdi
callq 0x3642
leaq 0x8(%rsp), %rdi
callq 0x3bfe
leaq 0x38(%rsp), %rdi
callq 0x36d2
leaq 0x198(%rsp), %rdi
callq 0x36f2
leaq 0x150(%rsp), %rdi
callq 0x3b46
xorl %eax, %eax
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1cd82(%rip), %rdi     # 0x20088
leaq 0x1cd1b(%rip), %rsi     # 0x20028
leaq 0x1cd1f(%rip), %rcx     # 0x20033
pushq $0x31
popq %rdx
callq 0x2150
leaq 0x1cce1(%rip), %rdi     # 0x20004
leaq 0x1ccfe(%rip), %rsi     # 0x20028
leaq 0x1cd02(%rip), %rcx     # 0x20033
pushq $0x16
jmp 0x3316
movq 0x2ccb4(%rip), %rdi     # 0x2fff0
leaq 0x1cd67(%rip), %rsi     # 0x200aa
callq 0x2210
movq %rax, %rdi
callq 0x20e0
callq 0x2130
leaq 0x1cdc7(%rip), %rdi     # 0x20123
leaq 0x1ccc5(%rip), %rsi     # 0x20028
leaq 0x1ccc9(%rip), %rcx     # 0x20033
pushq $0x54
jmp 0x3316
leaq 0x1cdb8(%rip), %rdi     # 0x2012d
leaq 0x1ccac(%rip), %rsi     # 0x20028
leaq 0x1ccb0(%rip), %rcx     # 0x20033
pushq $0x76
jmp 0x3316
leaq 0x1cdd0(%rip), %rdi     # 0x2015e
leaq 0x1cc93(%rip), %rsi     # 0x20028
leaq 0x1cc97(%rip), %rcx     # 0x20033
pushq $0x7e
jmp 0x3316
leaq 0x1cde9(%rip), %rdi     # 0x20193
leaq 0x1cc77(%rip), %rsi     # 0x20028
leaq 0x1cc7b(%rip), %rcx     # 0x20033
movl $0x82, %edx
callq 0x2150
leaq 0x1cd64(%rip), %rdi     # 0x2012d
leaq 0x1cc58(%rip), %rsi     # 0x20028
leaq 0x1cc5c(%rip), %rcx     # 0x20033
pushq $0x5f
jmp 0x3316
leaq 0x1cd79(%rip), %rdi     # 0x2015e
leaq 0x1cc3c(%rip), %rsi     # 0x20028
leaq 0x1cc40(%rip), %rcx     # 0x20033
pushq $0x67
jmp 0x3316
leaq 0x1cdc4(%rip), %rdi     # 0x201c5
leaq 0x1cc20(%rip), %rsi     # 0x20028
leaq 0x1cc24(%rip), %rcx     # 0x20033
movl $0x8d, %edx
callq 0x2150
leaq 0x1cdb9(%rip), %rdi     # 0x201d9
leaq 0x1cc01(%rip), %rsi     # 0x20028
leaq 0x1cc05(%rip), %rcx     # 0x20033
movl $0x8e, %edx
callq 0x2150
leaq 0x1cda9(%rip), %rdi     # 0x201e8
leaq 0x1cbe2(%rip), %rsi     # 0x20028
leaq 0x1cbe6(%rip), %rcx     # 0x20033
movl $0x8f, %edx
callq 0x2150
movq %rax, %r14
leaq 0xc0(%rsp), %rdi
callq 0x36d2
jmp 0x34de
jmp 0x34db
movq %rax, %r14
leaq 0x118(%rsp), %rdi
callq 0x3bfe
jmp 0x34c0
jmp 0x34bd
jmp 0x34cf
movq %rax, %r14
leaq 0x1e8(%rsp), %rdi
jmp 0x3499
movq %rax, %r14
leaq 0x218(%rsp), %rdi
callq 0x36bc
jmp 0x34de
jmp 0x34db
jmp 0x34a4
movq %rax, %r14
jmp 0x34eb
jmp 0x34f7
jmp 0x34af
jmp 0x34bd
movq %rax, %r14
jmp 0x3502
jmp 0x34db
jmp 0x34b8
movq %rax, %r14
jmp 0x350c
movq %rax, %r14
leaq 0xc0(%rsp), %rdi
callq 0x3642
jmp 0x34d2
movq %rax, %r14
leaq 0x8(%rsp), %rdi
jmp 0x34fd
jmp 0x352a
movq %rax, %r14
leaq 0x90(%rsp), %rdi
callq 0x36bc
leaq 0x8(%rsp), %rdi
callq 0x3642
jmp 0x34fa
movq %rax, %r14
movq %rbx, %rdi
callq 0x3bfe
leaq 0x38(%rsp), %rdi
callq 0x36d2
leaq 0x198(%rsp), %rdi
callq 0x36f2
leaq 0x150(%rsp), %rdi
callq 0x3b46
jmp 0x353c
jmp 0x352a
movq %rax, %r14
leaq 0x38(%rsp), %rdi
callq 0x20d0
jmp 0x353c
movq %rax, %r14
movq %r14, %rdi
callq 0x2340