{"trustable":true,"prependHtml":"\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027\\\\(\u0027, right: \u0027\\\\)\u0027, display: false},\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eAs we all know, machine scheduling is a very classical problem in computer \n science and has been studied for a very long history. Scheduling problems differ \n widely in the nature of the constraints that must be satisfied and the type \n of schedule desired. Here we consider a 2-machine scheduling problem.\u003cbr\u003e\n \u003cbr\u003e\n There are two machines A and B. Machine A has n kinds of working modes, which \n is called mode_0, mode_1, , mode_n-1, likewise machine B has m kinds of working \n modes, mode_0, mode_1, , mode_m-1. At the beginning they are both work at \n mode_0.\u003cbr\u003e\n \u003cbr\u003e\n For k jobs given, each of them can be processed in either one of the two machines \n in particular mode. For example, job 0 can either be processed in machine A \n at mode_3 or in machine B at mode_4, job 1 can either be processed in machine \n A at mode_2 or in machine B at mode_4, and so on. Thus, for job i, the constraint \n can be represent as a triple (i, x, y), which means it can be processed either \n in machine A at mode_x, or in machine B at mode_y.\u003cbr\u003e\n \u003cbr\u003e\n Obviously, to accomplish all the jobs, we need to change the machine\u0027s working \n mode from time to time, but unfortunately, the machine\u0027s working mode can only \n be changed by restarting it manually. By changing the sequence of the jobs and \n assigning each job to a suitable machine, please write a program to minimize \n the times of restarting machines. \u003c/p\u003e\n\u003cp\u003e\u003cbr\u003e\n \u003cb\u003eInput\u003c/b\u003e\u003cbr\u003e\n \u003cbr\u003e\n The input file for this program consists of several configurations. The first \n line of one configuration contains three positive integers: n, m (n, m \u0026lt; \n 100) and k (k \u0026lt; 1000). The following k lines give the constrains of the k \n jobs, each line is a triple: i, x, y.\u003cbr\u003e\n \u003cbr\u003e\n The input will be terminated by a line containing a single zero.\u003c/p\u003e\n\u003cp\u003e\u003cbr\u003e\n \u003cb\u003eOutput\u003c/b\u003e\u003cbr\u003e\n \u003cbr\u003e\n The output should be one integer per line, which means the minimal times of \n restarting machine.\u003c/p\u003e\n\u003cp\u003e\u003cbr\u003e\n \u003cb\u003eSample Input\u003c/b\u003e\u003c/p\u003e\n\u003cp\u003e5 5 10\u003cbr\u003e\n 0 1 1\u003cbr\u003e\n 1 1 2\u003cbr\u003e\n 2 1 3\u003cbr\u003e\n 3 1 4\u003cbr\u003e\n 4 2 1\u003cbr\u003e\n 5 2 2\u003cbr\u003e\n 6 2 3\u003cbr\u003e\n 7 2 4\u003cbr\u003e\n 8 3 3\u003cbr\u003e\n 9 4 3\u003cbr\u003e\n 0\u003c/p\u003e\n\u003cp\u003e\u003cb\u003e\u003cbr\u003e\n Sample Output\u003c/b\u003e\u003c/p\u003e\n\u003cp\u003e3\u003cbr\u003e\n\u003c/p\u003e"}}]}