輸出的時候發現不會對原來的矩陣排序,只好重新搞了一儲存邊的一維數組,然後排序。
#include
using namespace std;
const int N=256;
const int inf=0x7fffffff;
struct type
{
int b,c,f;
int no;
};
struct node
{
int no,f;
}g[20000+5];
int cmp(node a,node b)
{
return a.noQ;
Q.push(s);
while(!Q.empty()&&flag[t]==-1)
{
u=Q.front();
Q.pop();
for(i=s; i<=t; i++)
{
if(flag[i]!=-1) continue;
if(network[u][i].cnetwork[i][u].b)
{
flag[i]=0;
p[i]=u;
a[i]=min(a[u],network[i][u].f-network[i][u].b);
Q.push(i);
}
}
flag[u]=1;
}
if(flag[t]==-1||a[t]==0) break;
int k1=t,k2=p[k1];
while(1)
{
if(network[k2][k1].fsum1)
AccEdge[0][i].c=sum2-sum1,AccEdge[0][i].b=AccEdge[0][i].f=0;
else
AccEdge[i][n+1].c=sum1-sum2,AccEdge[i][n+1].b=AccEdge[i][n+1].f=0;
}
for(i=1; i<=n; i++)
for(j=1; j<=n; j++)
if(AccEdge[i][j].c!=inf)
{
AccEdge[i][j].c=AccEdge[i][j].c-AccEdge[i][j].b;
AccEdge[i][j].b=0;
}
Ford(AccEdge,0,n+1);
bool ok=1;
for(i=0; i<=n+1; i++)
{
if(AccEdge[0][i].c!=inf&&AccEdge[0][i].f!=AccEdge[0][i].c)
ok=0;
}
if(!ok) printf(NO
);
else
{
int tp=0;
printf(YES
);
for(i=1; i<=n; i++)
for(j=1; j<=n; j++)
if(Edge[i][j].c!=inf)
{
Edge[i][j].f=AccEdge[i][j].f+Edge[i][j].b;
g[tp].f=Edge[i][j].f;
g[tp].no=Edge[i][j].no;
tp++;
}
sort(g,g+tp,cmp);
for(i=0;i