1143: [CTSC2008] Sacrifice River time limit:10 Sec Memory limit:162 MB
submit:1878 solved:937
[Submit] [Status] [Discuss] Description
In the Far East, there is a mysterious nation, claiming to be the Y clan. They lived on the water for generations and Long Wan-wei God. Every major celebration, the Y tribe will be on the water to hold a grand festival. We can think of the Y-family residential system as a network of fork and channel. Each channel is connected to two fork crossings, and the water flows in a fixed direction within the channel. Obviously, there is no circulation in the water system (describe an example of a circulation).
Because of the large number of reasons, the Y-clan ritual will be held at multiple fork at the same time. For the respect of the Dragon King, the choice of these places of worship must be very cautious. To be precise, the Y-clan believes that if the flow of water can flow from one sacrificial point to another, then the sacrifice loses its divine meaning. The patriarch wants to choose as many places of worship as possible, on the basis of preserving the sacred nature of the sacrifice.
Input
The first line contains two integers separated by spaces N, M, respectively, indicating the number of fork and channel, the fork from 1 to n number. Next m line, each line contains two spaces separated by the integer U, V, describes a junction u and Fork v Channel, the flow direction is from u to v.
Output
The first line contains an integer k, which represents the maximum number of sacrificial points that can be selected.
Sample Input4 4
1 2
3 4
3 2
4 2Sample Output2
"Sample description"
In the water system given by the sample, there is no way to choose three or more three sacrificial sites. There are two scenarios for a test point with two sacrificial sites:
Select fork 1 and fork 3 (example output second row), select Fork 1 and Fork 4.
Currents can flow from any fork to fork 2. If a sacrificial site is established at Fork 2, no other fork can establish a sacrificial site.
However, in the optimal selection of a sacrificial site we can establish two sacrificial sites, so fork 2 can not establish a sacrificial site. For other fork
There is at least one optimal solution. Select the fork as the sacrificial point, so the output is 1011. HINT
For each test point: If you only output the correct number of selected sacrificial sites, you will get the score of the test point 30%, and if you only output the correct number of sacrificial points and a feasible scheme, then you will get the test point 60% score; If your output is completely correct, Then you will get the score of the test point 100%
"Data size" N≤100 M≤1 000
Source: This problem is converted, it becomes we want to find the largest independent set. Maximum independent set = Two graph points-minimum point overlay = longest anti-chain length = minimum chain overlay (path cannot intersect) chain to a collection of points, any two x x, y on the chain, or y to reach Y, or X to reach X. The chain is a collection of points, with any two x x, y on the chain, × cannot reach Y, and y cannot reach X. Then we run a delivery closure, and X can reach Y. And then re-compose the x to reach the y link. Run a maximum match, and then the total number of points minus the maximum match ... Dinic and Hungary can both ... I'm writing about Hungary:
1#include <bits/stdc++.h>2 using namespacestd;3bitset< the> a[ the];4bitset< the>Vis;5 intbf[ the],n,f[ the][ the];6 intRead ()7 {8 ints=0, fh=1;CharCh=GetChar ();9 while(ch<'0'|| Ch>'9'){if(ch=='-') fh=-1; ch=GetChar ();}Ten while(ch>='0'&&ch<='9') {s=s*Ten+ (ch-'0'); ch=GetChar ();} One returns*fh; A } - intXylintu) - { the intv; - for(v=1; v<=n;v++) - { - if(a[u][v]!=0&&vis[v]==0) + { -vis[v]=1; + if(Xyl (bf[v]) = =1|| bf[v]==0) A { atbf[v]=u; - return 1; - } - } - } - return 0; in } - intMain () to { + intM,i,j,x,y,ans; -N=read (); m=read (); the //For (i=1;i<=n;i++) a[i][i]=1; * for(i=1; i<=m;i++) $ {Panax NotoginsengX=read (); y=read (); -a[x][y]=1; the } + for(i=1; i<=n;i++) A { the for(j=1; j<=n;j++) + { - if(A[j][i]) a[j]|=A[i]; $ } $ } - /*For (i=1;i<=n;i++) - { the For (j=1;j<=n;j++) - {Wuyi if (a[i][j]&&i!=j) f[i][j]=1; the } - }*/ Wumemset (BF,0,sizeof(BF)); -ans=0; About for(i=1; i<=n;i++) $ { - Vis.reset (); -ans+=xyl (i); - } Aprintf"%d", N-ans); + fclose (stdin); the fclose (stdout); - return 0; $}
View Code
Bzoj 2718: [Violet 4] Graduation trip && Bzoj 1143: [CTSC2008] sacrificial river delivery closure, binary map matching, Hungary, Bitset