标签:
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 7278 | Accepted: 4318 |
Description
Input
Output
Sample Input
2 4 3 3 4 1 3 2 3 3 3 1 3 1 2 2 3
Sample Output
2 1
Source
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <iostream> 5 #include <vector> 6 #include <queue> 7 #include <cmath> 8 #include <set> 9 using namespace std; 10 11 #define N 205 12 13 int max(int x,int y){return x>y?x:y;} 14 int min(int x,int y){return x<y?x:y;} 15 int abs(int x,int y){return x<0?-x:x;} 16 17 int n, m; 18 bool visited[N]; 19 vector<int>ve[N]; 20 int from[N]; 21 22 int march(int u){ 23 int i, j, k, v; 24 for(i=0;i<ve[u].size();i++){ 25 v=ve[u][i]; 26 if(!visited[v]){ 27 visited[v]=true; 28 if(from[v]==-1||march(from[v])){ 29 from[v]=u; 30 return 1; 31 } 32 } 33 } 34 return 0; 35 } 36 37 main() 38 { 39 int t, i, j, k; 40 int u, v; 41 cin>>t; 42 while(t--){ 43 44 scanf("%d %d",&n,&m); 45 for(i=0;i<=n;i++) ve[i].clear(); 46 for(i=0;i<m;i++){ 47 scanf("%d %d",&u,&v); 48 ve[u].push_back(v); 49 } 50 memset(from,-1,sizeof(from)); 51 int num=0; 52 for(i=1;i<=n;i++){ 53 memset(visited,false,sizeof(visited)); 54 if(march(i)) num++; 55 } 56 printf("%d\n",n-num); 57 } 58 }
标签:
原文地址:http://www.cnblogs.com/qq1012662902/p/4638452.html