JZOJ 3423. [NOIP2013 Simulation] Cl2 Vani and hide and seek

Time Limits: 1000 ms  Memory Limits: 262144 KB  Detailed Limits 

Description

vani and cl2 hide and seek in the midst of the woods ......

these woods have a house N, M bar to have roads, formed a directed acyclic graph.

Woods tree very dense enough to block the view, but looked along the road, but it is visibility. If you can reach B from A house along the road to go, then the people in A and B in to be able to saw each other.

Between any two cl2 are now to be selected in this house, Block N, Block K as a hiding spot, but also a rarity in cl2 vani as a hiding spot inside the house looking for, in order to avoid being seen vani, cl2 requirements of the K point of hiding the path is not connected.

To make it harder to find their own vani, cl2 want to know the maximum number of points can elect to hide?

Input

The first line of two integers N, M.

The next two rows each integers M rows x, y, represents a directed path from x to y.

Output

An integer K, represents the number of hiding up to the selected point.

Sample Input

4 4
1 2
3 2
3 4
4 2

Sample Output

2

Data Constraint

For 20% of the data, N≤10, M <= 20.

For 60% of the data, N≤100, M <= 1000.

To 100% of the data, N≤200, M <= 30000,1 < = x, y <= N.

 

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #define maxn 210
 5 using namespace std;
 6 int n,m,g[maxn][maxn],ans,match[maxn];
 7 bool f[maxn];
 8 int Dfs(int s)
 9 {
10     for(int i=1;i<=n;i++)
11       if(f[i]==0&&g[s][i]==1)
12         {
13           f[i]=1;
14           if(match[i]==0||Dfs(match[i]))
15             {
16               match[i]=s;
17               return 1;
18             }
19         }
20     return 0;
21 }
22 int main()
23 {
24     scanf("%d%d",&n,&m);
25     int x,y;ans=n;
26     for(int i=1;i<=m;i++)
27       {
28           scanf("%d%d",&x,&y);
29           g[x][y]=1;
30       }
31     for(int k=1;k<=n;k++)
32       for(int i=1;i<=n;i++)
33         for(int j=1;j<=n;j++)
34           g[i][j]=g[i][j]||(g[i][k]&&g[k][j]);
35     for(int i=1;i<=n;i++)
36       {
37           memset(f,0,sizeof(f));
38           ans-=Dfs(i);
39       }
40     printf("%d\n",ans);
41     return 0;
42 }

Guess you like

Origin www.cnblogs.com/anbujingying/p/11297601.html