POJ 3469 min cut Dual Core CPU

Source: Internet
Author: User

Test instructions

A dual-core CPU runs n modules, each of which costs AI and bi for each module running on two cores.

At the same time, there is M-to-module data exchange, if the two modules are not running on the same core requires additional cost.

Minimum cost for running N modules.

Analysis:

This is a set partitioning problem, dividing the two modules into two sets, a module in a collection running on kernel A, and one running on the nuclear b.

Add a source point S and a meeting point T, each of which has an edge over the source and sink points, and the capacity is spent running on that core.

Then between two module pairs the capacity is a two-way side for extra cost.

A cut in the figure corresponds to the division of a set, and the minimum cut is the minimum total cost.

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5#include <vector>6#include <queue>7 using namespacestd;8 9 Const intMAXN =20000+Ten;Ten Const intINF =0x3f3f3f3f; One  A intN, S, T; - intN, M; -  the structEdge - { -     int  from, to, cap, flow; -Edge (intUintVintCintf): from(U), to (v), Cap (c), Flow (f) {} + }; -  +Vector<edge>edges; Avector<int>G[MAXN]; at  - voidInit () - { - edges.clear (); -      for(inti =0; I < n; i++) g[i].clear (); - } in  - voidAddedge (intUintVintc) to { +Edges.push_back (Edge (U, V, C,0)); -Edges.push_back (Edge (V, U,0,0)); the     intm =edges.size (); *G[u].push_back (M-2); $G[v].push_back (M-1);Panax Notoginseng } -  the BOOLVIS[MAXN]; + intD[MAXN], CUR[MAXN]; A  the BOOLBFS () + { -memset (Vis,false,sizeof(Vis)); $Vis[s] =true; $queue<int>Q; - Q.push (s); -D[s] =0; the  -      while(!q.empty ())Wuyi     { the         intU =Q.front (); Q.pop (); -          for(inti =0; I < g[u].size (); i++) Wu         { -edge& e =Edges[g[u][i]]; About             intv =e.to; $             if(!vis[v] && e.cap >E.flow) -             { -VIS[V] =true; -D[V] = D[u] +1; A Q.push (v); +             } the         } -     } $  the     returnVis[t]; the } the  the intDFS (intUinta) - { in     if(U = = T | | a = =0)returnA; the     intFlow =0, F; the      for(int& i = Cur[u]; I < g[u].size (); i++) About     { theedge& e =Edges[g[u][i]]; the         intv =e.to; the         if(D[v] = = D[u] +1&& (f = DFS (V, Min (A, e.cap-e.flow))) >0) +         { -Flow + =F; theE.flow + =F;BayiA-=F; theedges[g[u][i]^1].flow-=F; the             if(A = =0) Break; -         } -     } the     returnflow; the } the  the intMaxflow () - { the     intFlow =0; the      while(BFS ()) the     {94memset (cur,0,sizeof(cur)); theFlow + =DFS (S, INF); the     } the     returnflow;98 } About  - intMain ()101 {102      while(SCANF ("%d%d", &n, &m) = =2)103     {104n = n +2; the init ();106s =0, T = N +1;107          for(inti =1; I <= N; i++)108         {109             intA, B; scanf"%d%d", &a, &b); the Addedge (S, I, a);111 Addedge (i, T, b); the         }113          while(m--) the         { the             intA, B, w; scanf"%d%d%d", &a, &b, &W); the Addedge (A, B, W);117 Addedge (b, A, w);118         }119  -printf"%d\n", Maxflow ());121     }122 123     return 0;124}
code June

POJ 3469 min cut Dual Core CPU

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.