poj2594 Treasure Exploration(可相交最小路径覆盖)
来源:互联网 发布:什么是编程环境 编辑:程序博客网 时间:2024/05/16 15:50
可相交最小路径覆盖,用floyd求出原图的传递闭包,即如果a到b有路径,那么就加边a->b。然后就转化成了最小不相交路径覆盖问题。
#include <cstdio>#include <cstring>using namespace std;#define ll long long#define N 510#define inf 0x3f3f3f3finline int read(){ int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();} while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar(); return x*f;}int n,m,h[N],num=0,bf[N],ans=0;bool f[N],mp[N][N];struct edge{ int to,next;}data[250010];inline bool find(int x){ for(int i=h[x];i;i=data[i].next){ int y=data[i].to;if(f[y]) continue; f[y]=1;if(!bf[y]||find(bf[y])){bf[y]=x;return 1;} }return 0;}inline void add(int x,int y){ data[++num].to=y;data[num].next=h[x];h[x]=num;}int main(){// freopen("a.in","r",stdin); while(1){ n=read();m=read();if(!n) break; memset(bf,0,sizeof(bf));ans=0; memset(h,0,sizeof(h));num=0;memset(mp,0,sizeof(mp)); while(m--){ int x=read(),y=read();mp[x][y]=1; }for(int k=1;k<=n;++k) for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) mp[i][j]|=mp[i][k]&mp[k][j]; for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) if(i!=j&&mp[i][j]) add(i,j); for(int i=1;i<=n;++i){ memset(f,0,sizeof(f));if(find(i)) ans++; }printf("%d\n",n-ans); }return 0;}
阅读全文
0 0
- poj2594 Treasure Exploration(可相交最小路径覆盖)
- POJ2594 Treasure Exploration(最小路径覆盖)
- 可重叠的最小路径覆盖 poj2594 Treasure Exploration
- POJ2594-Treasure Exploration(最小路径覆盖变形)
- poj2594 Treasure Exploration【最小路径覆盖】
- POJ Treasure Exploration(DAG最小可相交路径覆盖)
- Poj 2594 Treasure Exploration【可相交最小路径覆盖】
- POJ2594 Treasure Exploration【二分图最小路径覆盖】【Floyd】
- poj2594(可相交最小路径覆盖)
- poj2594-Treasure Exploration(最小路径覆盖,最大匹配,floyed(优化))
- poj2594——Treasure Exploration(闭包+最小路径覆盖)
- POJ-2594-Treasure Exploration(可重点最小路径覆盖)
- POJ-2594-Treasure Exploration-(路径相交的最小路径覆盖+闭包传递)
- poj2594 Treasure Exploration 最小路径覆盖=顶点数-最大匹配数
- POJ2594 Treasure Exploration(二分图最小路径覆盖,传递闭包)
- POJ2594 Treasure Exploration 最小点覆盖题目[有重复点]
- poj 2594 Treasure Exploration(最小路径覆盖(可重点)+floyd)
- POJ 2594 Treasure Exploration (最小路径覆盖+传递闭包(解决可重点))
- MySql支持Emoji表情存储
- windows下如何查看tensorflow是否使用gpu
- 阿里HBase超详实践总结 | 一文读懂大数据时代的结构化存储
- IOP面向接口编程
- Mariadb数据库的性能优化及安全性配置
- poj2594 Treasure Exploration(可相交最小路径覆盖)
- git: 用 ssh协议 代替 http协议,加速传送
- org.hibernate.LazyInitializationException: could not initialize proxy
- JS预解析
- C++中三中继承区别
- Pandas drop_duplicates的inplace属性
- 学习敏捷
- 译丨2017 Web 开发者学习路线图
- 使用python计算方差——pandas.series.std()