bzoj 1143: [CTSC2008]祭祀river

这是最大独立集??最小点覆盖??(反正就是总数减去匈牙利算出来的就是)

这个题加一个Floyd建边就行

 1 #include<bits/stdc++.h>
 2 #define N 200005
 3 #define LL long long
 4 #define inf 0x3f3f3f3f
 5 #define ls tr[x][0]
 6 #define rs tr[x][1]
 7 using namespace std;
 8 inline int ra()
 9 {
10     int x=0,f=1; char ch=getchar();
11     while (ch<'0' || ch>'9') {if (ch=='-') f=-1; ch=getchar();}
12     while (ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
13     return x*f;
14 }
15 bool mp[505][505];
16 int T,y[505],lk[505],n,m,ans;
17 int dfs(int x)
18 {
19     for (int i=1; i<=n; i++)
20         if (mp[x][i] && y[i]!=T)
21         {
22             y[i]=T;
23             if (lk[i]==0 || dfs(lk[i]))
24             {
25                 lk[i]=x;
26                 return 1;
27             }
28         }
29     return 0; 
30 }
31 int main()
32 {
33     n=ra(); m=ra();
34     for (int i=1; i<=m; i++)
35         mp[ra()][ra()]=1;
36     for (int k=1; k<=n; k++)    
37         for (int i=1; i<=n; i++)
38             for (int j=1; j<=n; j++)
39                 if (mp[i][k] && mp[k][j]) mp[i][j]=1;
40     for (int i=1; i<=n; i++)
41     {
42         T++; ans+=dfs(i);
43     }
44     cout<<n-ans;
45 }

 

posted @ 2017-03-01 08:09  ws_ccd  阅读(147)  评论(0编辑  收藏  举报