标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3200 Accepted Submission(s): 1897
1 #include<cstdio> 2 #include<cstring> 3 using namespace std; 4 #define N 210 5 struct Edge{ 6 int to; 7 bool in; 8 int next; 9 }edge[N*N]; 10 int head[N]; 11 int Enct; 12 bool visited[N*N]; 13 int link[N]; 14 void init() 15 { 16 memset(head,-1,sizeof(head)); 17 Enct = 0; 18 } 19 void add(int from , int to) 20 { 21 edge[Enct].to = to; 22 edge[Enct].next = head[from]; 23 edge[Enct].in = true; 24 head[from] = Enct++; 25 edge[Enct].to = from; 26 edge[Enct].in = true; 27 edge[Enct].next = head[to]; 28 head[to] = Enct++; 29 } 30 bool find(int u) 31 { 32 for(int i = head[u] ; i!=-1 ; i = edge[i].next) 33 { 34 if(edge[i].in ==false) continue; 35 int v = edge[i].to; 36 if(visited[v]) continue; 37 visited[v] = true; 38 if(link[v] == -1||find(link[v])) 39 { 40 link[v] = u;//回溯,每次都将边反转 41 //printf("%d ",link[v]); 42 return true; 43 } 44 } 45 return false; 46 } 47 int k; 48 int n; 49 int solve() 50 { 51 memset(link,-1,sizeof(link)); 52 int res = 0; 53 for(int i = 1 ;i <= n ;i++)//注意点的编号是从1开始的 54 { 55 memset(visited,0,sizeof(visited)); 56 visited[i] = true; 57 if(find(i)){ res++; 58 //printf("%d ",link[i]); 59 //puts(""); 60 } 61 } 62 return res; 63 } 64 int main() 65 { 66 int m; 67 int c = 0; 68 while(~scanf("%d%d%d",&n,&m,&k)) 69 { 70 c++; 71 init(); 72 for(int i = 0 ; i < k ;i++) 73 { 74 int x, y; 75 scanf("%d%d",&x,&y); 76 add(x,y+n); 77 } 78 int sum = solve(); 79 int ans = 0 ; 80 for(int i = 0 ;i < k ; i++) 81 { 82 edge[i<<1|1].in = false; 83 edge[i<<1].in = false; 84 int tm = solve(); 85 if(tm!=sum) ans++; 86 edge[i<<1|1].in = true; 87 edge[i<<1].in = true; 88 } 89 printf("Board %d have %d important blanks for %d chessmen.\n",c,ans,sum); 90 } 91 return 0; 92 }
标签:
原文地址:http://www.cnblogs.com/shanyr/p/4761748.html