zoukankan      html  css  js  c++  java
  • poj3041 Asteroids

    二分图。对于每个点,将他的 x 与 y 连一条边,求最小点覆盖
    二分图最小点覆盖等于最大匹配

    #include <iostream>
    #include <cstring>
    #include <cstdio>
    using namespace std;
    int n, k, hea[505], cnt, lnk[1005], ans, uu, vv;
    bool vis[1005];
    struct Edge{
    	int too, nxt;
    }edge[10005];
    void add_edge(int fro, int too){
    	edge[++cnt].nxt = hea[fro];
    	edge[cnt].too = too;
    	hea[fro] = cnt;
    }
    bool dfs(int x){
    	for(int i=hea[x]; i; i=edge[i].nxt){
    		int t=edge[i].too;
    		if(!vis[t]){
    			vis[t] = true;
    			if(!lnk[t] || dfs(lnk[t])){
    				lnk[t] = x;
    				return true;
    			}
    		}
    	}
    	return false;
    }
    int main(){
    	cin>>n>>k;
    	while(k--){
    		scanf("%d %d", &uu, &vv);
    		add_edge(uu, vv+n);
    	}
    	for(int i=1; i<=n; i++){
    		memset(vis, 0, sizeof(vis));
    		if(dfs(i))	ans++;
    	}
    	cout<<ans<<endl;
    	return 0;
    }
    
  • 相关阅读:
    线程同步-使用CountDownEvent类
    WPF 依赖属性和附加属性
    ef core
    Razor语法
    python-爬虫
    ftp
    泛型
    结对编程作业
    第三次作业
    第二次作业
  • 原文地址:https://www.cnblogs.com/poorpool/p/8315327.html
Copyright © 2011-2022 走看看