0_0_29404494_12544.cpp:1:2845: fatal error: GCC4.9.2/x86_64-w64-mingw32/include/c++/bits/stdc++.h>usin: Invalid argument
#include<bits/stdc++.h>using namespace std;const int maxn=1505;const int inf=1e9;int head[maxn],d[maxn],tol,level[maxn],iter[maxn];int from[maxn*maxn],to[maxn*maxn],cost[maxn*maxn];bool vis[maxn];struct edge{ int to,cost,next;}rode[maxn*maxn];struct node{ int to,cap,rev;};vector<node>G[maxn];void add(int a,int b,int c){ rode[tol].to=b; rode[tol].cost=c; rode[tol].next=head[a]; head[a]=tol++;}void spfa(){ for(int i=0;i<maxn;i++) d[i]=1e9; memset(vis,0,sizeof(vis)); d[1]=0; queue<int>P;P.push(1); while(!P.empty()) { int v=P.front();P.pop(); vis[v]=0; for(int i=head[v];i!=-1;i=rode[i].next) { edge e=rode[i]; if(d[e.to]>d[v]+e.cost) { d[e.to]=d[v]+e.cost; if(!vis[e.to]) { P.push(e.to); vis[e.to]=1; } } } }}void add_edge(int from,int to,int cap){ G[from].push_back((node){to,cap,G[to].size()}); G[to].push_back((node){from,0,G[from].size()-1});}void ADD(){ for(int i=0;i<maxn;i++) G[i].clear(); for(int i=0; ;i++) { int a=from[i],b=to[i],c=cost[i]; if(a==0&&b==0&&c==0)break; if(d[a]-d[b]==c) add_edge(b,a,1); else if(d[b]-d[a]==c) add_edge(a,b,1); }}void bfs(int s){ memset(level,-1,sizeof(level)); level[s]=0; queue<int>P; P.push(s); while(!P.empty()) { int v=P.front();P.pop(); for(int i=0;i<G[v].size();i++) { node e=G[v][i]; if(e.cap>0&&level[e.to]<0) { level[e.to]=level[v]+1; P.push(e.to); } } }}int dfs(int v,int t,int f){ if(v==t)return f; for(int &i=iter[v];i<G[v].size();i++) { node &e=G[v][i]; if(e.cap>0&&level[e.to]>level[v]) { int d=dfs(e.to,t,min(f,e.cap)); if(d>0) { e.cap-=d; G[e.to][e.rev].cap+=d; return d; } } } return 0;}int max_flow(int v,int t){ ADD(); int flow=0; while(1) { bfs(v); if(level[t]<0)return flow; memset(iter,0,sizeof(iter)); int f; while((f=dfs(v,t,inf))>0)flow+=f; }}int main(){ int T;scanf("%d",&T); while(T--) { tol=0; memset(head,-1,sizeof(head)); int n;scanf("%d",&n); for(int i=0; ;i++) { int a,b,c; scanf("%d%d%d",&a,&b,&c); from[i]=a;to[i]=b;cost[i]=c; if(a==0&&b==0&&c==0)break; add(a,b,c);add(b,a,c); } spfa(); if(n==1) { printf("0\n"); continue; } printf("%d\n",max_flow(1,n));//若n==1则1到1无法跑最大流 } return 0;}
^
compilation terminated.
|