标签:cli pen logs printf isp begin walk should org
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 8625 | Accepted: 5155 |
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 <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <cstring> 5 6 inline void read(int &x) 7 { 8 x = 0;char ch = getchar(), c = ch; 9 while(ch < ‘0‘ || ch > ‘9‘)c = ch, ch = getchar(); 10 while(ch <= ‘9‘ && ch >= ‘0‘)x = x * 10 + ch - ‘0‘, ch = getchar(); 11 if(c == ‘-‘)x = -x; 12 } 13 14 const int INF = 0x3f3f3f3f; 15 16 struct Edge 17 { 18 int u,v,next; 19 Edge(int _u, int _v, int _next){u = _u, v = _v, next = _next;} 20 Edge(){} 21 }edge[100000]; 22 23 int head[10000], cnt; 24 25 inline void insert(int a, int b) 26 { 27 edge[++cnt] = Edge(a,b,head[a]); 28 head[a] = cnt; 29 } 30 31 int n,m,lk[10000],b[10000]; 32 33 int dfs(int u) 34 { 35 for(register int pos = head[u];pos;pos = edge[pos].next) 36 { 37 int v = edge[pos].v; 38 if(b[v])continue; 39 b[v] = 1; 40 if(lk[v] == -1 || dfs(lk[v])) 41 { 42 lk[v] = u; 43 return 1; 44 } 45 } 46 return 0; 47 } 48 49 int xiongyali() 50 { 51 int ans = 0; 52 memset(lk, -1, sizeof(lk)); 53 for(register int i = 1;i <= n;++ i) 54 { 55 memset(b, 0, sizeof(b)); 56 ans += dfs(i); 57 } 58 return ans; 59 } 60 61 int t; 62 63 int main() 64 { 65 read(t); 66 for(;t;--t) 67 { 68 memset(edge, 0, sizeof(edge)); 69 memset(head, 0, sizeof(head)); 70 cnt = 0; 71 read(n), read(m); 72 register int tmp1,tmp2,i; 73 for(i = 1;i <= m;++ i) 74 { 75 read(tmp1), read(tmp2); 76 insert(tmp1, tmp2); 77 } 78 printf("%d\n", n - xiongyali()); 79 } 80 return 0; 81 }
标签:cli pen logs printf isp begin walk should org
原文地址:http://www.cnblogs.com/huibixiaoxing/p/7585606.html