/*
http://acm.hdu.edu.cn/showproblem.php?pid=3729 I'm Telling the Truth
二分图最大匹配
*/
#include <iostream>
#include <string>
#include <cstring>
#include <map>
using namespace std;
#define CLR(c,v) memset(c,v,sizeof(c))
const int N = 1e4 + 5;
const int M = 6e5 + 5;
struct Vertex{ int head; }V[N];
struct Edge{ int v,next; }E[M];
int top,match[N];
bool vis[N];
void add(int u,int v){
E[top].v = v;
E[top].next = V[u].head;
V[u].head = top++;
}
bool dfs(int u){
for(int i = V[u].head ; ~i ; i = E[i].next){
int v = E[i].v;
if(!vis[v]){
vis[v] = true;
if(!match[v] || dfs(match[v]) ){
match[v] = u;
return true;
}
}
}
return false;
}
void maxMatch(int n){ /// 点数
CLR(match,0);
int ans = 0;
int tmp[100] , cnt = 0;
for(int i = n ; i >= 1 ; i--){
CLR(vis,0);
if(dfs(i)){
++ans;
tmp[++cnt] = i;
}
}
cout << ans << endl;
for(int i = cnt ; i >= 2 ; i--)
cout << tmp[i] << " ";
cout << tmp[1] << endl;
}
int main(){
//freopen("in.txt","r",stdin);
int T;cin >> T;while(T--){
int n;cin >> n;
CLR(V,-1);
top = 0;
for(int i = 1 ; i <= n ; i++){
int a, b;
cin >> a >> b;
for(int j = a ; j <= b ; j++)
add(i,j);
}
maxMatch(n);
}
return 0;
}
HDU 3729 I'm Telling the Truth -- 二分图最大匹配 输出方案
最新推荐文章于 2019-05-19 21:44:33 发布