【ural1109】二分图&前向星

511体侧,只能补测了GG

/*
* File: 666.c
* Author: Jiawen Bao
* Date: 
*
* Purpose: to solve a very easy problem
* https://666.com
*/

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define REP(i,n) for(int i=0;i MII;
typedef map MSI;
typedef vector VI;
typedef vector VS;
typedef vector VD;
typedef pair PII;
typedef long long ll;
typedef unsigned int UI;
typedef long double LD;
typedef unsigned long long ULL;

#define MAXM 50010
#define MAXN 1010
 
struct EDGE{
	int next;   //下一条边的存储下标 
	int to;     //这条边的终点 
	int w;      //权值 
}; 
EDGE edge[MAXM];
 
int m,n,k,cnt;
int head[MAXN];  //head[i]表示以i为起点的第一条边 
int cx[1010],cy[1010],vis[1010];
void Add(int u, int v, int w) {  //起点u, 终点v, 权值w 
	edge[++cnt].next = head[u];
	edge[cnt].w = w;
	edge[cnt].to = v;
	head[u] = cnt;    //第一条边为当前边 
} 

int dfs(int u){
	for(int i=head[u]; i!=0; i=edge[i].next){
		int v = edge[i].to;
		if(!vis[v]){
			vis[v] = 1;
			if(cy[v]==-1||dfs(cy[v])){
				cy[v] = u;
				cx[u] = v;
				return 1;
			}
		}
	}
	return 0;
}
int main(){
	int ans=0;
	cin>>m>>n>>k;
	memset(cx,-1,sizeof(cx));
	memset(cy,-1,sizeof(cy));
	while(k--){
		int p1,p2;
		cin>>p1>>p2;
		Add(p1,p2,1);
	}
	for(int i=1;i<=m;i++){
		if(cx[i]==-1){
			memset(vis,0,sizeof(vis));
			ans+=dfs(i);
		}
	}
	cout<

你可能感兴趣的:(世界你好)