标签:
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 14852 Accepted Submission(s): 6544
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 #define N 1010 6 int head[N]; 7 struct Edge{ 8 int to; 9 int next; 10 }edge[N*N]; 11 int Enct; 12 void init() 13 { 14 memset(head,-1,sizeof(head)); 15 Enct = 0; 16 } 17 void add(int from , int to) 18 { 19 edge[Enct].to = to; 20 edge[Enct].next = head[from]; 21 head[from] = Enct++; 22 edge[Enct].to = from; 23 edge[Enct].next = head[to]; 24 head[to] = Enct++; 25 } 26 bool vis[N*N]; 27 int k , n , m ; 28 int rm[N*N]; 29 30 bool list(int s) 31 { 32 for(int j = head[s] ; j != -1 ; j = edge[j].next) 33 { 34 int tm = edge[j].to; 35 if(vis[tm]==1) continue; 36 vis[tm] = 1;//记得标记为未访问 37 if(rm[tm]==-1||list(rm[tm])){ 38 rm[tm] = s; 39 return 1; 40 } 41 } 42 return 0; 43 } 44 int MaxMatch() 45 { 46 int ans = 0; 47 for(int i = 0 ; i < m ; i++) 48 { 49 memset(vis,0,sizeof(vis)); 50 vis[i] = 1;//要标记刚进入的点是未访问的 51 if(list(i)) ans++; 52 } 53 return ans; 54 } 55 int main() 56 { 57 while(~scanf("%d%d%d",&k,&m,&n)) 58 { 59 init(); 60 for(int i = 0 ;i < k ;i++) 61 { 62 int x, y; 63 scanf("%d%d",&x,&y); 64 add(x-1,y+m-1);//他们构成了一张图,所以不可以让两个点有相同的编号 65 } 66 int a ; 67 scanf("%d",&a); 68 memset(rm,-1,sizeof(rm)); 69 int ans = MaxMatch(); 70 printf("%d\n",ans); 71 } 72 return 0; 73 }
标签:
原文地址:http://www.cnblogs.com/shanyr/p/4893986.html