gragh
http://blog.sina.com.cn/s/blog_6cf509db0100uy5n.html
网络流题目集合
1: http://blog.csdn.net/shahdza/article/details/7779537
2:http://blog.sina.com.cn/s/blog_5e518b010100m6w8.html
http://blog.csdn.net/liwen_7/article/details/7298736
http://blog.csdn.net/justlovetao/article/details/6697171
http://ycool.com/post/m2uybbf(查分约束)
bellman
#include<iostream>
#include<cstring>
using namespace std;
struct Node
{
int u,v;
double ruv;
double need;
}e[500];
int n,s,m;
double v;
int all;
double dist[111];
bool bellman()
{
int i,j;
memset(dist,0,sizeof(dist));
dist[s]=v;
for(i=0;i<n;i++)
{
for(j=0;j<all;j++)
{
if(dist[e[j].v]<(dist[e[j].u]-e[j].need)*e[j].ruv)
dist[e[j].v]=(dist[e[j].u]-e[j].need)*e[j].ruv;
}
}
for(j=0;j<all;j++)
{
if(dist[e[j].v]<(dist[e[j].u]-e[j].need)*e[j].ruv)
break;
}
if(j<all)
return true;
return false;
}
int main()
{
int i;
int x,y;
double nxy,cxy,nyx,cyx;
while(cin>>n>>m>>s>>v)
{
all=0;
for(i=0;i<m;i++)
{
cin>>x>>y>>cxy>>nxy>>cyx>>nyx;
e[all].u=x;e[all].v=y;e[all].ruv=cxy;e[all++].need=nxy;
e[all].u=y;e[all].v=x;e[all].ruv=cyx;e[all++].need=nyx;
}
if(bellman())
cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}
堆void slift(int r[],int low,int high)
{
int i=low.j=2*i;
int t=r[i];
while(j<=high)
{
if(j<high&&r[j]<r[j+1])
j++;
if(tmp<r[j])
{
r[i]=r[j];
i=j;
j=2*i;
}
else break;
}
r[i]=tmp;
}
void Heapsort(int r[],int n)
{
int i;
int t;
for(i=n/2;i>=1;i--)//循环建立初始堆
slift(r,i,n);
for(i=n;i>=2;i--)//进行n-1 趟堆排序的元素个数减1
{
t=r[1]; //将最后一个元素同当前区间内r[1]兑换
r[1]=r[i];
r[i]=t;
slift(r,1,i-1);
}
}