Misaka_Azusa @ 2018-05-12 17:02:08
同学连样例都过不去的代码也能AC?
QwQ
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int MAXN=10010,MAXM=200020;
int n,m,s,t,ans,Head[MAXN],num=-1,que[MAXN*100],head,tail,deep[MAXN];
struct NODE{
int to,next,w;
} e[MAXM];
inline int read()
{
int x=0,f=1; char c=getchar();
while(c<'0'||'9'<c) {if(c=='-') f=-1; c=getchar();}
while('0'<=c&&c<='9') {x=(x<<3)+(x<<1)+c-'0'; c=getchar();}
return x*f;
}
inline void add()
{
int x=read(),y=read(),w=read();
e[++num].to=y;
e[num].w=w;
e[num].next=Head[x];
Head[x]=num;
e[++num].to=x;
e[num].w=0;
e[num].next=Head[y];
Head[y]=num;
}
inline bool bfs()
{
memset(deep,-1,sizeof(deep));
head=tail=0;
que[++tail]=s;
deep[s]=0;
while(head<tail)
{
int u=que[++head];
for(int i=Head[u];i;i=e[i].next)
if(e[i].w>0&&deep[e[i].to]==-1)
{
deep[e[i].to]=deep[u]+1;
que[++tail]=e[i].to;
if(e[i].to==t) break;
}
}
if(deep[t]!=-1) return 1;
return 0;
}
inline int dfs(int now,int cap)
{
if(!cap||now==t) return cap;
int flow=0,f;
for(int i=Head[now];i;i=e[i].next)
if(e[i].w>0&&deep[e[i].to]==deep[now]+1&&(f=dfs(e[i].to,min(cap,e[i].w))))
{
cap-=f;
flow+=f;
e[i].w-=f;
e[i^1].w+=f;
if(!cap) break;
}
return flow;
}
inline void Dinic()
{
while(bfs())
ans+=dfs(s,0x7fffffff);
}
int main()
{
scanf("%d%d%d%d",&n,&m,&s,&t);
for(int i=1;i<=m;i++)
add();
Dinic();
printf("%d\n",ans);
return 0;
}
by ylxmf2020 @ 2018-05-12 17:18:21
%%%%
by ylxmf2020 @ 2018-05-12 17:18:36
样例就是hack数据了.....
by Misaka_Azusa @ 2018-05-12 22:06:03
qwq