没题解
2024-07-17 15:44:42
发布于:北京
14阅读
0回复
0点赞
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int N = 1e6 + 5;
int n, x, y, T;
int vis[N], match[N];
vector<int> G[N];
bool dfs(int x){
if (vis[x] == T) return false;
vis[x] = T;
for (int to : G[x]){
if (!match[to] || dfs(match[to])){
match[to] = x;
return true;
}
}
return false;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
for (int i=1; i<=n; i++){
cin >> x >> y;
G[x].push_back(i);
G[y].push_back(i);
}
for (T=1; T<=10005; T++){
if (!dfs(T)){
cout << T - 1 << endl;
return 0;
}
}
return 0;
}
这里空空如也
有帮助,赞一个