标签:namespace name using 顶点 include 题意 check algo init
题意:求最小的染色顶点数满足所有的边至少有个一端点被染色
2015四川省赛,过题数17/120+,还以为是什么难题,这不就是裸的二分图最小点覆盖吗..
掏出了尘封一年的破板子
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
const int maxn = 503;
int r,c,cnt;
vector<int> G[maxn];
bool check[maxn];
int match[maxn];
void init(){
memset(G,0,sizeof G);
memset(match,-1,sizeof match);
cnt = 0;
}
bool dfs(int u){
for(int i = 0; i < G[u].size(); i++){
int v = G[u][i];
if(check[v]) continue;
check[v] = 1;
if(match[v]==-1||dfs(match[v])){
match[u]=v;
match[v]=u;
return 1;
}
}
return 0;
}
int main(){
int n,k;
while(scanf("%d%d",&n,&k)!=EOF){
init();
for(int i = 0; i < k; i++){
scanf("%d%d",&r,&c);
G[r].push_back(c);
G[c].push_back(r);//
}
for(int i = 1; i <= n; i++){
memset(check,0,sizeof check);
if(match[i]==-1&&dfs(i)) cnt++;
}
printf("%d\n",cnt);
}
return 0;
}
标签:namespace name using 顶点 include 题意 check algo init
原文地址:https://www.cnblogs.com/caturra/p/8904777.html