Poj 1325 Machine Schedule binary match, which can be done using the maximum stream

Source: Internet
Author: User

For machine scheduling problems, the same task can be completed in different modes on two different machines, A and B. the initial mode of the machine is mode_0, but changing from any mode to another mode requires restarting the machine. the minimum number of reboots required to complete all tasks.

 

 

========================================================== ==============

For tasks (I, x, y), we connect an edge between machine A mode_x and machine B mode_y. in this way, the question becomes a bipartite graph. Our goal is to complete all tasks, that is, to overwrite all line segments. The question requires the least point to be selected, this allows each line segment to have at least one endpoint selected (this task is completed). This is the minimum point overwrite model. The answer is the maximum matching of the Bipartite Graph.

 


However, I used the largest flow of water to solve this problem. I can add A super source point and A super sink point respectively, and each mode of the B server connects an edge to an edge, then there is the maximum stream.


Note that at the beginning, all the machines are in Mode 0 !!
For (int I = 0; I <k; I ++)
{
Scanf ("% d", & a, & B, & c );
If (B * c! = 0)
Map [B] [c] = true;
}


Below is my code

 

/******** PRO: POJ 1325TIT: Machine ScheduleDAT: 2013-08-16-15.50AUT: UKeanEMA: huyocan@163.com ****/# include <iostream> # include <cstdio> # include <algorithm> # include <cstring> # include <queue> # define INF 1e9using namespace std; queue <int> que; // The int s, t queues to be used for extensive search; // Source and Sink int flow [505] [505]; // residual traffic int p [505]; // The parent node array int a [505] of the wide search record path; // minimum residual volume on the path int cap [505] [505]; // capacity network int ans; // maximum stream int read () {int n, m, k; cin> n; If (! N) return 0; cin> m> k; s = 0; t = m + n + 1; // 1-> n is A n + 1-> n + m is Bmemset (cap, 0, sizeof (cap); for (int I = 0; I <k; I ++) {int a, B, c; cin> a> B> c; if (B * c! = 0) // remember that the initial state is 0 0, so as long as one of B or c is 0, in this case, you do not need to store the cap [B + 1] [c + n + 1] = 1;} for (int I = 1; I <= n; I ++) cap [s] [I] = 1; for (int I = n + 1; I <= n + m; I ++) cap [I] [t] = 1; return 1;} int deal () // The augmented path algorithm is not explained in detail, for more information, see my first blog on network stream // streams (flow, 0, sizeof (flow); ans = 0; while (1) {memset (, 0, sizeof (a); a [s] = INF; que. push (s); while (! Que. empty () {int u = que. front (); que. pop (); for (int v = 0; v <= t; v ++) if (! A [v] & cap [u] [v]-flow [u] [v]> 0) {p [v] = u; que. push (v); a [v] = min (a [u], cap [u] [v]-flow [u] [v]); // minimum residual traffic on the path} if (a [t] = 0) break; for (int u = t; u! = S; u = p [u]) {flow [p [u] [u] + = a [t]; flow [u] [p [u]-= a [t];} ans + = a [t];} cout <ans <endl; return ans ;} int main () {while (read () deal (); return 0 ;}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.