Problem with a forward ring coverage

Source: Internet
Author: User

Reproduced from here

  Give you a weighted graph of n-vertex m-edges, and you want to divide the graph into one or more disjoint, forward loops. And all the points are covered by a ring. Ask you what is the minimum sum of the total ownership value of the ring?

The answer is: there is a maximum weight override for the Ring = optimal match.

Analysis:

  We divide any vertex I into two, namely I and I '. If the original image has a i->j edge, then the dichotomy has a i->j ' edge.

Here are a few conclusions:

① if the original image can be covered by multiple disjoint circular loops, then there must be a complete match between the two graphs. They are necessary and sufficient for each other, that is to say , if there is a complete match of the binary map, then the original image must be covered by several rings that do not want to cross. 

② If there is a forward loop covering the maximum weighted value of the original image, then the optimal match of the binary graph must be this value. That is, the weighted maximum of the forward loop coverage is equal to the best matching value of the modified graph in numerical value.

      Because the forward loop overlay corresponds to a complete match of a binary graph, and the weighted value of the complete match is equal to the weighted value of the forward ring coverage, it is not possible to lose the matching of the maximum weight for the optimal match.

  ( assuming that the forward loop of the original is (1->2->3->1) and (6->5->4->6), then the complete match of the binary graph is 1->2 ' 2->3 ' 3->1 ' 6->5 ' 5- >4 ' 4->6 ')

(assuming that the complete match of the binary graph is 1->2 ' 2->3 ' 3->1 ' 6->5 ' 5->4 ' 4->6 ') then the forward loop of the original is (1->2->3->1) and (6->5-> 4->6))

For example HDU1853:

Now the original question requires a minimum-weight match, we take the weights of all known edges to negative numbers, and those that do not exist we take-inf (negative infinity). If a complete match exists, then the absolute value of the optimal matching weights we find is definitely <inf. and the absolute value is the minimum weight match.

If the complete match does not exist, then the absolute value of the optimal matching weights must be >inf. ( think about it) or so, if there is a match in the final match, any one of the matching edges with a negative infinity edge, then the optimal match does not exist (that is, the complete match does not exist)

1#include <cstdio>2#include <cstring>3#include <queue>4 #define_CLR (x, y) memset (x, y, sizeof (x))5 #defineINF 0x3f3f3f3f6 #defineN 10057 using namespacestd;8 9 intMat[n][n], match[n];Ten intLx[n], ly[n]; One intSlack[n]; A BOOLUsed_x[n], used_y[n]; - intN, M; -  the BOOLDfsintx) - { -USED_X[X] =true; -      for(intI=1; i<=n; i++) +     { -         if(Used_y[i])Continue; +         intt = lx[x] + ly[i]-Mat[x][i]; A         if(t==0) at         { -Used_y[i] =true; -             if(match[i]==-1||DFS (Match[i])) -             { -Match[i] =x; -                 return true; in             } -         } to         ElseSlack[i] =min (slack[i], t); +     } -     return false; the } *  $ intKM ()Panax Notoginseng { -_CLR (Match,-1); the_CLR (Ly,0); +      for(intI=1, J; i<=n; i++) A          for(j=1, Lx[i]=-inf; j<=n; J + +) theLx[i] =Max (Lx[i], mat[i][j]); +      for(intx=1; x<=n; X + +) -     { $ _clr (Slack, INF); $          while(1) -         { -_CLR (used_x,0); the_CLR (Used_y,0); -             if(Dfs (x)) Break;Wuyi             intD=INF; the              for(intI=1; i<=n; i++) -                 if(!used_y[i] && d>Slack[i]) WuD =Slack[i]; -              for(intI=1; i<=n; i++) About                 if(Used_x[i]) $Lx[i]-=D; -              for(intI=1; i<=n; i++) -                 if(Used_y[i]) -Ly[i] + =D; A                 ElseSlack[i]-=D; +         } the     } -     intans=0; $      for(intI=1; i<=n; i++) the     { the         if(match[i]==-1|| Mat[match[i]][i]==-inf)return-1; theAns + =Mat[match[i]][i]; the     } -     return-ans; in } the intMain () the { About     intm, A, B, C; the      while(~SCANF ("%d%d", &n, &m)) the     { the          for(intI=1; i<=n; i++) +          for(intj=1; j<=n; J + +) -mat[i][j]=-INF; the          while(m--)Bayi         { thescanf"%d%d%d", &a, &b, &c); theMAT[A][B] = max (Mat[a][b],-c); -         } -printf"%d\n", KM ()); the     } the     return 0; the}

Problem with a forward ring coverage

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.