rt
顺便请求加大时限到1.5s
TLE3个点
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=405,maxm=15005;namespace in{
#ifdef faster
char buf[1<<21],*p1=buf,*p2=buf;
inline int getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
#else
inline int getc(){return getchar();}
#endif
template <typename T>inline void read(T& t){
t=0;int f=0;char ch=getc();while (!isdigit(ch)){if(ch=='-')f = 1;ch=getc();}
while(isdigit(ch)){t=t*10+ch-48;ch = getc();}if(f)t=-t;
}
template <typename T,typename... Args> inline void read(T& t, Args&... args){read(t);read(args...);}
}
namespace out{
char buffer[1<<21];int p1=-1;const int p2 = (1<<21)-1;
inline void flush(){fwrite(buffer,1,p1+1,stdout),p1=-1;}
inline void putc(const char &x) {if(p1==p2)flush();buffer[++p1]=x;}
template <typename T>void write(T x) {
static char buf[15];static int len=-1;if(x>=0){do{buf[++len]=x%10+48,x/=10;}while (x);}else{putc('-');do {buf[++len]=-(x%10)+48,x/=10;}while(x);}
while (len>=0)putc(buf[len]),--len;
}
}
int n,m,tot=1,head[maxn];
struct node
{
int x,w,v,u,nxt;
}e[maxm<<1];
void add(int x,int y,int w,int v)
{
e[++tot].v=y;
e[tot].u=x;
e[tot].x=v;
e[tot].w=w;
e[tot].nxt=head[x];
head[x]=tot;
}
queue<int> q;
int dis[maxn],bk[maxn],pre[maxn],zz;
int spfa()
{
while(!q.empty())
q.pop();
memset(pre,0,sizeof pre);
memset(bk,0,sizeof bk);
memset(dis,0x7f,sizeof dis);
q.push(1);
// for(int i=1;i<=n;i++)
// cout<<dis[i]<<endl;
dis[1]=0;
bk[1]=1;
while(!q.empty())
{
int x=q.front();
bk[x]=0;
q.pop();
for(int i=head[x];i;i=e[i].nxt)
{
int v=e[i].v;
// cout<<v<<endl;
// cout<<v<<' '<<e[i].w<<' '<<dis[x]<<' '<<bk[v]<<' '<<dis[v]<<endl;
if(e[i].x>0&&dis[v]>dis[x]+e[i].w )
{
// cout<<"QWQ"<<endl;
dis[v]=dis[x]+e[i].w;
if(!bk[v])
q.push(v);
pre[v]=i;
bk[v]=1;
}
}
}
// cout<<dis[n]<<endl;
return dis[n]<=1926081719260817;
}
signed main()
{
int ans=0,s=0;
in::read(n,m);
for(int i=1;i<=m;i++)
{
int s,t,x,y;
in::read(s,t,x,y);
add(s,t,y,x);
add(t,s,-y,0);
}
while(spfa())
{
++zz;
// cout<<"QWQ"<<endl;
int mi=1926081719260817,x=n;
// cout<<pre[1]<<endl;
while(x!=1)
{
mi=min(e[pre[x]].x,mi);
// cout<<x<<endl;
x=e[pre[x]].u;
}
x=n;
while(x!=1)
{
int v=pre[x];
e[pre[x]].x-=mi;
e[pre[x]^1].x+=mi;
ans+=e[pre[x]].w*mi;
// cout<<e[v].w<<endl;
// cout<<x<<endl;
x=e[pre[x]].u;
}
// cout<<mi<<endl;
s+=mi;
}
printf("%lld %lld",s,ans);
return 0;
}