Language: C++

//poj 3469 2987  å¿«äº
//////////èç¹å·ã1ï¼nã,source,sink ä¸ºå¶ä¸­ä»»æç¹
#include <cstdio>   
#include <cstring> 
#define maxn 132
typedef __int64 LL;
LL inf;
using namespace std;
struct edge
{
    int u,v,next, pre; LL f;
}e[100000];
int num,rnum; int n,m,N; int source,sink;
int head[maxn],rhead[maxn], start[maxn];
int d[maxn],numb[maxn];
int p[maxn];
void Init()
{
    memset(head,-1,sizeof(head));///åé¾è¡¨å¿é¡»ç½® -1
    memset(rhead,-1,sizeof(rhead));
    memset(p,-1,sizeof(p));
    num=0;///å¿é¡»ä¸º0
}
void BFS()
{
    int i,j;
    for(i=1;i<=N;i++)//////////èç¹å·ã1ï¼nã
    {
        d[i]=N;///åå§åæ¯ä¸ªèç¹çè·ç¦»ä¸ºæ ç©·å¤§ nå³å¯
        numb[i]=0;
    }
    int Q[maxn],head(0),tail(0);
    d[sink]=0;//æsinkæ¾å¥éå
    numb[0]=1;
    Q[++tail]=sink;
    while(head<tail)
    {
        i=Q[++head];
        for(j=rhead[i];j!=-1;j=e[j].pre)
        {
            if(e[j].f==0||d[e[j].u]<N)
                continue;///ä»¥åå°±å°è¾¾è¿æèæ²¡æå¯æµéäº
            d[e[j].u]=d[i]+1;
            numb[d[e[j].u]]++;
            Q[++tail]=e[j].u;
        }
    }
}
LL Augment()
{
    int i; LL tmp=inf;
    for(i=p[sink];i!=-1;i=p[e[i].u])
    {
        if(tmp>e[i].f)
            tmp=e[i].f;
    }
    for(i=p[sink];i!=-1;i=p[e[i].u])
    {
        e[i].f-=tmp;////æ­£è¾¹ï¼åè¾¹ç¸ç»§çï¼ä¸­é´å·® 1
        e[i^1].f+=tmp;
    }
    return tmp;
}
int Retreat(int &i)
{
    int tmp,j,mind(N-1);
    for(j=head[i];j!=-1;j=e[j].next)////æ¾æå°çè·¯å¾æ å·
    {
        if(e[j].f>0&&d[e[j].v]<mind)
            mind=d[e[j].v];
    }
    tmp=d[i];///ä¿®æ¹ç¸åº è·¯å¾æ å·çä¸ªæ°
    d[i]=mind+1;
    numb[tmp]--;
    numb[d[i]]++;
    if(i!=source)////ååèç¹
        i=e[p[i]].u;
    return numb[tmp];////è¿åæåièç¹çè·¯å¾æ å·dãiã çä¸ªæ°,æ­å±åç»æ
}
LL maxflow()
{
    LL flow(0);
	int i,j;
    BFS();
    for(i=1;i<=N;i++)
        start[i]=head[i];
	//memcpy(start,head,sizeof(start));
    i=source;
    while(d[source]<N)
    {
        for(j=start[i];j!=-1;j=e[j].next)
            if(e[j].f>0&&d[i]==d[e[j].v]+1)
                break;
        if(j!=-1)////æ¾å°å¢å¹¿çè·¯å¾
        {
            start[i]=j;
            p[e[j].v]=j;
            i=e[j].v;
            if(i==sink)///å¢å¹¿å°äºsink
            {
                flow+=Augment();
                i=source;
            }
        }
        else ////æ²¡æå¢å¹¿è·¯ï¼
        {
            start[i]=head[i];
            if(Retreat(i)==0)////éè¦éæ°æ è®°ï¼åãiï¼jãä¸­jæå°çè·¯å¾æ å·
                break;
        }
    }
    return flow;
}

void addedge(int a,int b,LL c)
{
	e[num].f=c;e[num].u=a; e[num].v=b;
    e[num].next=head[a];head[a]=num;
    e[num].pre=rhead[b];rhead[b]=num;  
    num++;

    e[num].u=b;e[num].v=a;e[num].f=0;
    e[num].next=head[b];head[b]=num;
    e[num].pre=rhead[a];rhead[a]=num;
	num++;
}
LL g[maxn][maxn];
inline LL min(LL a, LL b) { return a<b?a:b; }
int main()
{
    int a,b; LL c;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
		if (n==0 && m==0) break;
		N=n;
		memset(g, 0, sizeof(g));
		LL ans=0;
		for (int i=0; i<m; i++)
		{
			scanf("%d %d %lld", &a, &b, &c);
		    a++; b++;
			g[a][b]+=c;
		    //ans+=c;
		    if (c>0) ans+=c; else ans-=c;
        }
		inf=ans;
		for (int i=2; i<=n; i++)
		{
			source=1;
			sink=i;
			Init();
			LL tmp=0;
			for (int j=1; j<=n; j++) 
				for (int k=1; k<=n; k++)
			{
				if (j==k) continue;
				if (g[j][k]<0) tmp+=g[j][k];
				if (g[j][k]>0) addedge(j, k, g[j][k]);
			}
			ans=min(ans, maxflow()+tmp);
		}
        printf("%lld\n", ans);
    }
    return 0;
}

Compiler output:
a.cc:6:9: error: '__int64' does not name a type; did you mean '__int64_t'?
    6 | typedef __int64 LL;
      |         ^~~~~~~
      |         __int64_t
a.cc:7:1: error: 'LL' does not name a type; did you mean 'NULL'?
    7 | LL inf;
      | ^~
      | NULL
a.cc:11:24: error: 'LL' does not name a type; did you mean 'NULL'?
   11 |     int u,v,next, pre; LL f;
      |                        ^~
      |                        NULL
a.cc: In function 'void BFS()':
a.cc:41:21: error: 'struct edge' has no member named 'f'
   41 |             if(e[j].f==0||d[e[j].u]<N)
      |                     ^
a.cc: At global scope:
a.cc:49:1: error: 'LL' does not name a type; did you mean 'NULL'?
   49 | LL Augment()
      | ^~
      | NULL
a.cc: In function 'int Retreat(int&)':
a.cc:69:17: error: 'struct edge' has no member named 'f'
   69 |         if(e[j].f>0&&d[e[j].v]<mind)
      |                 ^
a.cc: At global scope:
a.cc:80:1: error: 'LL' does not name a type; did you mean 'NULL'?
   80 | LL maxflow()
      | ^~
      | NULL
a.cc:115:26: error: 'LL' has not been declared
  115 | void addedge(int a,int b,LL c)
      |                          ^~
a.cc: In function 'void addedge(int, int, int)':
a.cc:117:16: error: 'struct edge' has no member named 'f'
  117 |         e[num].f=c;e[num].u=a; e[num].v=b;
      |                ^
a.cc:122:34: error: 'struct edge' has no member named 'f'
  122 |     e[num].u=b;e[num].v=a;e[num].f=0;
      |                                  ^
a.cc: At global scope:
a.cc:127:1: error: 'LL' does not name a type; did you mean 'NULL'?
  127 | LL g[maxn][maxn];
      | ^~
      | NULL
a.cc:128:8: error: 'LL' does not name a type; did you mean 'NULL'?
  128 | inline LL min(LL a, LL b) { return a<b?a:b; }
      |        ^~
      |        NULL
a.cc: In function 'int main()':
a.cc:131:14: error: 'LL' was not declared in this scope
  131 |     int a,b; LL c;
      |              ^~
a.cc:136:24: error: 'g' was not declared in this scope
  136 |                 memset(g, 0, sizeof(g));
      |                        ^
a.cc:137:19: error: expected ';' before 'ans'
  137 |                 LL ans=0;
      |                   ^~~~
      |                   ;
a.cc:140:54: error: 'c' was not declared in this scope
  140 |                         scanf("%d %d %lld", &a, &b, &c);
      |                                                      ^
a.cc:144:30: error: 'ans' was not declared in this scope
  144 |                     if (c>0) ans+=c; else ans-=c;
      |                              ^~~
a.cc:144:43: error: 'ans' was not declared in this scope
  144 |                     if (c>0) ans+=c; else ans-=c;
      |                                           ^~~
a.cc:146:17: error: 'inf' was not declared in this scope; did you mean 'int'?
  146 |                 inf=ans;
      |                 ^~~
      |                 int
a.cc:146:21: error: 'ans' was not declared in this scope
  146 |                 inf=ans;
      |                     ^~~
a.cc:152:27: error: expected ';' before 'tmp'
  152 |                         LL tmp=0;
      |                           ^~~~
      |                           ;
a.cc:157:48: error: 'tmp' was not declared in this scope
  157 |                                 if (g[j][k]<0) tmp+=g[j][k];
      |                                                ^~~
a.cc:160:38: error: 'maxflow' was not declared in this scope
  160 |                         ans=min(ans, maxflow()+tmp);
      |                                      ^~~~~~~
a.cc:160:48: error: 'tmp' was not declared in this scope
  160 |                         ans=min(ans, maxflow()+tmp);
      |                                                ^~~
a.cc:160:29: error: 'min' was not declared in this scope; did you mean 'main'?
  160 |                         ans=min(ans, maxflow()+tmp);
      |                             ^~~
      |                             main