hdu 3987 Harry Potter and the Forbidden Forest 求割边最少的最小割
来源:互联网 发布:淘宝闲鱼钓鱼网站源码 编辑:程序博客网 时间:2024/05/21 18:41
题意:
思路:
由于题目需要乘上最大的边数 而题目的最大边数有100000 所以数会很大 需要用64.在错了无限多次后终于搞对了。记得是他的花费要超int
还有就是记得用c++编译不用g++不然inf会超long int
先给出方法1的:耗时间78ms
#include<iostream> #include<cstdio> #include<memory.h> #include<cmath> using namespace std; #define MAXN 5010 #define MAXE 1000100 #define INF 100000000000000000 int ne,nv,tmp,s,t,index; struct Edge{ int next,pair,v; __int64 cap,fLow; }edge[MAXE]; int net[MAXN]; __int64 ISAP() { int numb[MAXN],dist[MAXN],curedge[MAXN],pre[MAXN]; __int64 cur_fLow,max_fLow;int u,tmp,neck,i; memset(dist,0,sizeof(dist)); memset(numb,0,sizeof(numb)); memset(pre,-1,sizeof(pre)); for(i = 1 ; i <= nv ; ++i) curedge[i] = net[i]; numb[nv] = nv; max_fLow = 0; u = s; while(dist[s] < nv) { if(u == t) { cur_fLow = INF+1; for(i = s; i != t;i = edge[curedge[i]].v) { if(cur_fLow > edge[curedge[i]].cap) { neck = i; cur_fLow = edge[curedge[i]].cap; } } for(i = s; i != t; i = edge[curedge[i]].v) { tmp = curedge[i]; edge[tmp].cap -= cur_fLow; edge[tmp].fLow += cur_fLow; tmp = edge[tmp].pair; edge[tmp].cap += cur_fLow; edge[tmp].fLow -= cur_fLow; } max_fLow += cur_fLow; u = neck; } for(i = curedge[u]; i != -1; i = edge[i].next) if(edge[i].cap > 0 && dist[u] == dist[edge[i].v]+1) break; if(i != -1) { curedge[u] = i; pre[edge[i].v] = u; u = edge[i].v; }else{ if(0 == --numb[dist[u]]) break; curedge[u] = net[u]; for(tmp = nv,i = net[u]; i != -1; i = edge[i].next) if(edge[i].cap > 0) tmp = tmp<dist[edge[i].v]?tmp:dist[edge[i].v]; dist[u] = tmp + 1; ++numb[dist[u]]; if(u != s) u = pre[u]; } } return max_fLow; }void addedge(int u,int v,__int64 f){ edge[index].next = net[u]; edge[index].v = v; edge[index].cap = f; edge[index].fLow = 0; edge[index].pair = index+1; net[u] = index++; edge[index].next = net[v]; edge[index].v = u; edge[index].cap = 0; edge[index].fLow = 0; edge[index].pair = index-1; net[v] = index++; } int main() { int i,j,np,nc,m,n; int a,b,d,k,vaL; int te; int cases=1; scanf("%d",&te); while(te--) { scanf("%d%d",&n,&m); nv=n; index=1; if(n==0 && m==0) return 0; s = 1; t = n; memset(net,-1,sizeof(net)); for(i=1;i<=m;i++) { int u,v,d; __int64 c; scanf("%d%d%I64d%d",&u,&v,&c,&d); u++,v++; addedge(u,v,c*100001+1); if(d) addedge(v,u,c*100001+1); } __int64 ans=ISAP(); printf("Case %d: %I64d\n", cases++, ans % 100001); } return 0; }
- hdu 3987 Harry Potter and the Forbidden Forest 求割边最少的最小割
- HDU 3987 Harry Potter and the Forbidden Forest (求割边最少的最小割)
- HDU 3987 Harry Potter and the Forbidden Forest(最小割的最少割边数)
- HDU 3987 Harry Potter and the Forbidden Forest(最小割中的最少割边)经典
- HDU 3987 Harry Potter and the Forbidden Forest 最小割
- 【HDU】3987 Harry Potter and the Forbidden Forest 最小割
- 【最小割】HDU 3987 Harry Potter and the Forbidden Forest
- hdu 3987 Harry Potter and the Forbidden Forest 最小割
- HDU--3987[Harry Potter and the Forbidden Forest] 求最小割集中的最小边数
- hdoj 3987 Harry Potter and the Forbidden Forest 【求所有最小割里面 最少的边数】
- hdu 3987 Harry Potter and the Forbidden Forest【网路流最小割模型】
- hdu 3987 Harry Potter and the Forbidden Forest (最小割)
- hdu 3987 Harry Potter and the Forbidden Forest//边数最小的最小割 2种解题方法
- HDU3987 Harry Potter and the Forbidden Forest最小割最少边Dinic
- hdu3987 Harry Potter and the Forbidden Forest 最小割割边最少
- HDU3987 Harry Potter and the Forbidden Forest(最小割)
- Harry Potter and the Forbidden Forest(割边最小的最小割)
- HDOJ 3987 - Harry Potter and the Forbidden Forest 设置偏移量,最小割
- 母亲的唠叨
- 6410红外遥控接口以及解码
- 嫣然一笑苦了情
- SICP习题解答2.17-2.23
- ChinaTest 2012中国软件测试大会
- hdu 3987 Harry Potter and the Forbidden Forest 求割边最少的最小割
- 最好的ico制作网站
- c#中结构体与类的比较
- 数据库外表
- 一枕落花香
- Codeforces Round #136 B
- phonegap+html5 激情奉献 bookstroe 源代码
- Xcode4.3开发第一个IOS应用实例(很详细)
- 红尘恋歌