您的位置:首页 > 其它

CodeForcesGym 100753B Bounty Hunter II

2015-10-05 19:30 246 查看

Bounty Hunter II

Time Limit: 5000ms
Memory Limit: 262144KB
This problem will be judged on CodeForcesGym. Original ID: 100753B
64-bit integer IO format: %I64d Java class name: (Any)

#include <bits/stdc++.h>
using namespace std;
const int maxn = 4010;
vector<int>g[maxn];
int Link[maxn],n;
bool used[maxn];
bool match(int u){
for(int i = g[u].size()-1; i >= 0; --i){
if(used[g[u][i]]) continue;
used[g[u][i]] = true;
if(Link[g[u][i]] == -1 || match(Link[g[u][i]])){
Link[g[u][i]] = u;
return true;
}
}
return false;
}
int main(){
int m;
while(~scanf("%d",&n)){
for(int i = 0; i < maxn; ++i) g[i].clear();
for(int i = 0; i < n; ++i){
scanf("%d",&m);
for(int j = 0,v; j < m; ++j){
scanf("%d",&v);
g[i].push_back(v + n);
}
}
memset(Link,-1,sizeof Link);
int ret = 0;
for(int i = 0; i < n; ++i){
memset(used,false,sizeof used);
if(match(i)) ++ret;
}
printf("%d\n",n - ret);
}
}
/*
4
1 1
1 2
0
1 1

6
0
1 2
2 4 5
1 2
0
0

5
1 4
1 4
1 4
1 4
0
*/


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: