跳到正文

zhengzihuai

1374687

庄生晓梦迷蝴蝶,望帝春心托杜鹃。

在洛谷打开
资料、奖项与版本

资料

编号
1374687
抓取

奖项

2025 CSP-J
一等奖
2025 CSP-S
二等奖
2024 CSP-J
二等奖
一个人

一个总是被自己的傻无语到的人

一个因不擅长利用自己

而被自己无语到的人


QQ号:3164558136QQ号 :3164558136

Codeforces号:Zihuai_ZhengCodeforces号 : Zihuai\_Zheng

Atcoder号:Zihuai_ZhengAtcoder号: Zihuai\_Zheng

vjudge号:Zihuai_Zhengvjudge号 : Zihuai\_Zheng

dmy号:_zzhdmy号 : \_zzh

acwing号:zzh_acwing号 : zzh\_

reddit号:zzh_cgreddit号 : zzh\_cg

云文件

一个旧闻

一张图片

一篇奇葩文章

一篇更奇葩的文章

一个查询用的网站

一个常用格式手册

一个更常用的格式手册

一部好看的电影;关键点:24分,30分,34分,52分。


一个有意思的视频

一篇报道

一份总结

一个下载镜像站

一个海外论坛


模板:

C++
#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:

C++
#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;
}

细节


还没有收录这位用户的文章。