Poj 2987 firing

Source: Internet
Author: User

Poj_2987

For the first question of this question, either the method of enlarging edge weight or the method of finding a link between DFS and S is limited to the individual level. At present, neither of the two practices proves correct, however, individuals prefer the second method.

In Edelweiss's network stream modeling summary, we have mentioned how to determine whether the minimum cut is unique. The reason for the occurrence of the least cut is not unique, part of which is due to a situation similar to this: s to 1 has an edge with a capacity of 1, and 1 to t also has an edge with a capacity of 1, after the minimum cut is done, the content of the two sides is changed to 0, that is to say, they can be regarded as cut edges, so 1 can be regarded as connected to S or t, in terms of this question, the fewer points that we want to connect to S, the better. In this case, we all think that point is connected to T, therefore, we will not continue to go down when the DFS encounters an edge with 0 content starting from S, because those points behind it are connected to T by default.

Of course, the above description is only for one point. Whether it can be promoted to all situations remains to be proved.

To sum up, I am confused when I first ask, So let's continue with the second question.

I think of two ways to deal with the second question:

① Start with converting to the largest weighted closed graph model: this topic actually expects a firing set so that no vertex in this set has an edge pointing to a vertex not in this set, that is to say, if we want to get a closed graph, we hope that the vertices and vertices of the set will be the largest. Naturally, it is the model of the largest weighted closed graph. For details about how to create the largest weighted closed graph model, refer to the application of the least cut model in the informatics competition by the National Training Team in 07 years.

② Start with minimum cut: We need to get a firing set and a set not firing, in addition, to satisfy the fact that there is no edge from the firing set pointing to the non-firing set, if the vertex that can finally be reached from S is viewed as the vertex in the firing set, other points that can reach t are considered as points in the set that are not firing, after the maximum stream is finished, the vertices in the firing set naturally do not point to the edges of vertices in the set that are not firing. Otherwise, the augmented path will be formed. In order to minimize the cost of a cut image, we need to minimize the cost. That is, we need to minimize the loss compared with the biggest profit. Next, we need to consider how each vertex connects to S and T, so we need to consider whether each vertex is put into S or put into T. For vertices with positive weights (assuming the value is X), if they are placed in T, the loss of X is equivalent to the loss of X relative to the maximum profit. That is to say, if the vertices and S are disconnected, the cost of X should be paid, so the capacity of connecting s to this point is the side of X, so that if this side is converted into a cut edge, then this point will be in the T Collection, because the edge is full, it is equivalent to paying the price of X. Negative weights are analyzed Similarly, so we will not repeat them here.

In addition, this question should use long when connecting to the INF edge, and INF should be large enough. Otherwise, because the Bi range in the question is large, the INF edge may be full, if the INF edge is full, it cannot be called the capacity as the INF edge ......

# Include <stdio. h> # Include < String . H> # Include <Algorithm> # Define Maxd 5010 # Define Maxm 130010 # Define INF 0x3f3f3f3f3f3f3fll Int  N, m, first [maxd], E, next [maxm], U [maxm], V [maxm];  Int  S, T, d [maxd], Q [maxd], work [maxd];  Long   Long Tot, flow [maxm];  Void Add ( Int X, Int Y, Long   Long  Z) {u [E] = X, V [e] = Y, flow [e] = Z; next [E] = First [X], first [x] = e ++ ;}  Void  Init (){  Int  I, X, Y; s = 0 , T = n +1  ; Memset (first, - 1 , Sizeof (First [ 0 ]) * (T + 1 ), E = 0  ; Tot = 0  ;  For (I = 1 ; I <= N; I ++ ) {Scanf (  " % D  " ,& X );  If (X> 0  ) {Tot + = X; add (S, I, x), add (I, S,  0  );}  Else   If (X < 0  ) Add (I, T, -X), add (t, I, 0 );}  For (I = 0 ; I <m; I ++ ) {Scanf (  "  % D  " , & X ,& Y); add (X, Y, INF), add (Y, X,  0  );}}  Int  BFS (){  Int I, j, rear = 0  ; Memset (D, - 1 , Sizeof (D [ 0 ]) * (T + 1  ); D [s] = 0 , Q [rear ++] = S;  For (I = 0 ; I <rear; I ++ )  For (J = first [Q [I]; J! =- 1 ; J = Next [J]) If (Flow [J] & D [V [J] =- 1  ) {D [V [J] = D [Q [I] + 1 , Q [rear ++] = V [J];  If (V [J] = T) Return   1  ;}  Return   0  ;}  Long   Long DFS (Int Cur, Long   Long  A ){  If (Cur = T) Return  A;  For ( Int & I = work [cur]; I! =- 1 ; I = Next [I])  If (Flow [I] & D [V [I] = d [cur] + 1  ) If ( Long   Long T = DFS (V [I], STD: min (A, flow [I]) {flow [I] -= T, flow [I ^ 1 ] + = T;  Return  T ;}  Return   0  ;}  Long   Long  Dinic (){ Long   Long Ans = 0  , T;  While  (BFS () {memcpy (work, first,  Sizeof (First [ 0 ]) * (T + 1  ));  While (T = DFS (S, INF) ans + = T ;}  Return Ans ;}  Void DFS ( Int Cur, Int & Num ){  Int  I; d [cur] = 1 , ++ Num;  For (I = first [cur]; I! =- 1 ; I = Next [I])  If (Flow [I] &!D [V [I]) DFS (V [I], num );}  Void  Solve (){  Int Num = 0  ;  Long   Long Ans = tot- Dinic (); memset (D,  0 , Sizeof (D [ 0 ]) * (T + 1  ); DFS (S, num); printf ( "  % D % LLD \ n  " , Num- 1  , ANS );}  Int  Main (){  While (Scanf ( "  % D  " , & N, & M) = 2  ) {Init (); solve ();}  Return   0 ;}

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.