【每日一题】游戏
[SCOI2010]游戏
https://ac.nowcoder.com/acm/problem/20566
题意:
思路
#include <cstdio> #include <vector> #include <cstring> #include <iostream> using namespace std; const int N = 1e4 + 10; const int M = 1e6 + 10; vector<int> G[N]; int n,now; bool match[M]; int used[M]; bool Hungary(int u){ for(int i = 0;i < G[u].size();i++){ int v = G[u][i]; if(used[v] != now){ used[v] = now; if(!match[v] || Hungary(match[v])){ match[v] = u; return 1; } } } return 0; } int main(){ scanf("%d",&n); for(int i = 1,u,v;i <= n;i++){ scanf("%d%d",&u,&v); G[u].push_back(i),G[v].push_back(i); } int ans = 0; for(int i = 1;i <= n;i++){ now = i; if(Hungary(i)) ans++; else break; } printf("%d\n",ans); return 0; }
每日一题 文章被收录于专栏
每题一题题目