一个人
一个总是被自己的傻无语到的人
一个因不擅长利用自己
而被自己无语到的人
一部好看的电影;关键点:24分,30分,34分,52分。
模板:
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef __int128 i8;
const ll N=1e5+5,mod=1e9+7,inf=(1ll<<60);
using namespace std;
int main(){
// ios::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
return 0;
}tmp:
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef __int128 i8;
const ll N=2e3+5,M=2e4+5,mod=1e9+7,inf=LLONG_MAX>>3;
using namespace std;
ll head[N],ver[M],nxt[M],fl[M],ufl[M],dfl[M],tot=1;
ll d[N],nw[N],inm[N],otm[N];
ll n,m,ss,tt,ans1,ans2;
bool flag=1;
vector <int> ne;
void add(ll u,ll v,ll w){
tot++,ver[tot]=v,fl[tot]=w,nxt[tot]=head[u],head[u]=tot;
}
bool mkd_bfs(ll s,ll t){
memset(d,0,sizeof(d));
queue<int> q;
d[s]=1,nw[s]=head[s],q.push(s);
while(q.size()){
ll u=q.front();
q.pop();
for(ll e=head[u],v=ver[e];e;e=nxt[e]){
if(fl[e]&&(!d[v])){
q.push(v);
d[v]=d[u]+1,nw[v]=head[v];
if(v==t)return 1;
}
}
}
return 0;
}
ll dinic(ll u,ll flow){
ll res=flow;
ll& e=nw[u];
for(ll v=ver[e];e;e=nxt[e],v=ver[e]){
if(!fl[e])continue;
if(d[v]!=d[u]+1) continue;
ll tmp=dinic(v,min(fl[e],res));
if(!tmp){
d[v]=0;
continue;
}
fl[e]-=tmp,fl[e^1]+=tmp,res-=tmp;
}
return flow;
}
ll mf(ll s,ll t){
ll res=0;
while(mkd_bfs(s,t)){
ll tmp;
while(tmp=dinic(s,inf))res+=tmp;
}
return res;
}
int main(){
// ios::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
cin>>n>>m>>ss>>tt;
for(int i=1;i<=m;i++){
ll u,v,l,r;
cin>>u>>v>>l>>r;
add(u,v,r-l),add(v,u,0);
ufl[tot>>1]=r,dfl[tot>>1]=l;
}
//2m+2,2m+3
add(tt,ss,inf),add(ss,tt,0);
ufl[tot>>1]=inf,dfl[tot>>1]=0;
ne.push_back(tot),ne.push_back(tot-1);
//
ll s_=n+1,t_=n+2;
for(ll u=1;u<=n;u++){
for(ll e=head[u],v=ver[e];e;e=nxt[e],v=ver[e]){
if(e&1)continue;
inm[v]+=dfl[e>>1],otm[v]+=dfl[e>>1];
}
}
for(ll u=1;u<=n;u++){
if(inm[u]==otm[u]) continue;
if(inm[u]>otm[u])add(s_,u,inm[u]-otm[u]),add(u,s_,0),ne.push_back(tot),ne.push_back(tot-1);
if(inm[u]<otm[u])add(u,t_,otm[u]-inm[u]),add(t_,u,0),ne.push_back(tot),ne.push_back(tot-1);
}
mf(s_,t_);
for(ll e=head[s_],v=ver[e];e;e=nxt[e],v=ver[e]){
if(e&1) continue;
flag&=(!fl[e]);
}
if(!flag){
cout<<'N';
return 0;
}
ans1=fl[2*m+3];
while(ne.size()){
ll tmp=ne.back();
ver[tmp]=0,fl[tmp]=0;
ne.pop_back();
}
ans2=mf(ss,tt);
cout<<ans1<<' '<<ans2;
return 0;
}