当前位置:网站首页>Blog Description & message board
Blog Description & message board
2022-07-25 04:50:00 【q779】
Better reading experience & Latest updates see https://q779.github.io/
CSDN Articles will be updated synchronously on , But some articles will not be updated ( obviously )
It may not be maintained in the future CSDN, It depends on me github.io Development
Welcome to leave a message .
It seems that too short articles are not allowed to be posted here , Then I'll post a few codes to recharge
// HLPP
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF 0x3f3f3f3f3f3f3f3f
// #define INF 0x3f3f3f3f
#define gc() readchar()
#define pc(a) putchar(a)
#define N (int)(2e3+15)
#define M (int)(3e5+15)
#define SIZ (int)(1e5+5)
char buf1[SIZ];
char *p1=buf1,*p2=buf1;
char readchar()
{
if(p1==p2)p1=buf1,p2=buf1+fread(buf1,1,SIZ,stdin);
return p1==p2?EOF:*p1++;
}
template<typename T>void read(T &k)
{
char ch=gc();T x=0,f=1;
while(!isdigit(ch)){
if(ch=='-')f=-1;ch=gc();}
while(isdigit(ch)){
x=(x<<1)+(x<<3)+(ch^48);ch=gc();}
k=x*f;
}
template<typename T>void write(T k)
{
static T stk[66];T top=0;
do{
stk[top++]=k%10,k/=10;}while(k);
while(top){
pc(stk[--top]+'0');}
}
struct Edge{
int v,w,next;};
vector<Edge> vec[N];
int n,m,s,t,now;
int gap[N],h[N],val[N],vis[N];
struct cmp
{
bool operator()(int a,int b)
{
return h[a]<h[b];}
};
priority_queue<int,vector<int>,cmp> q;
queue<int> b;
bool bfs()
{
memset(h,0x3f,(n+1)*sizeof(int));
b.push(t);h[t]=0;vis[t]=1;
while(!b.empty())
{
int u=b.front();b.pop();
vis[u]=0;
for(int i=0; i<vec[u].size(); i++)
{
int v=vec[u][i].v,j=vec[u][i].next;
if(vec[v][j].w>0&&h[v]>h[u]+1)
{
h[v]=h[u]+1;
if(!vis[v])
b.push(v),vis[v]=1;
}
}
}
return h[s]!=INF;
}
void relabel(int u)
{
h[u]=INF;
for(int i=0; i<vec[u].size(); i++)
{
int v=vec[u][i].v;
if(vec[u][i].w>0&&h[u]>h[v]+1)
h[u]=h[v]+1;
}
}
int HLPP()
{
if(!bfs())return -1;
h[s]=n;
for(int i=1; i<=n; i++)
if(h[i]!=INF)++gap[h[i]];
for(int i=0; i<vec[s].size(); i++)
{
int v=vec[s][i].v,w=vec[s][i].w,j=vec[s][i].next;
if(w>0)
{
val[s]-=w;
val[v]+=w;
vec[s][i].w-=w;
vec[v][j].w+=w;
if(!vis[v]&&v!=t&&v!=s)
q.push(v),vis[v]=1;
}
}
while(!q.empty())
{
int u=q.top();
q.pop();vis[u]=0;
if(h[u]==INF)continue; // !!!!!!!!!!!
for(int i=0; i<vec[u].size(); i++)
{
int v=vec[u][i].v,j=vec[u][i].next;
if(vec[u][i].w>0&&h[u]==h[v]+1)
{
int w=min(vec[u][i].w,val[u]);
val[u]-=w;
val[v]+=w;
vec[u][i].w-=w;
vec[v][j].w+=w;
if(!vis[v]&&v!=t&&v!=s)
q.push(v),vis[v]=1;
if(!val[u])break;
}
}
if(!val[u])continue;
if(!--gap[h[u]])
{
for(int i=1; i<=n; i++)
if(i!=s&&i!=t&&h[u]<h[i]&&h[i]<=n)
h[i]=n+1;
}
relabel(u);++gap[h[u]];
q.push(u);vis[u]=1;
}
return val[t];
}
signed main()
{
read(n);read(m);read(s);read(t);
for(int i=1,u,v,w; i<=m; i++)
{
read(u);read(v);read(w);
vec[u].push_back({
v,w,(int)vec[v].size()});
vec[v].push_back({
u,0,(int)vec[u].size()-1});
}
write(HLPP());pc('\n');
return 0;
}
边栏推荐
- The United States has launched 337 investigations on a number of Chinese companies: Bubugao is full of lying guns!
- [ CTF 学习 ] CTF 中的隐写集合 —— 图片隐写术
- ESWC 2018 | R-GCN:基于图卷积网络的关系数据建模
- In depth understanding of service
- Open source summer interview | "after 00" PMC member Bai Zeping
- Pychart configuration pyqt5
- Druid连接池——从0开始坚强的一点点的自学,Druid一点不懂的可以点进来,懂得别点进来,点进来你会嫌我啰嗦的
- How can I check if the number of RDS links in MySQL suddenly rises?
- 运筹学基础【一】 之 导论
- 盐粒和冰粒分不清
猜你喜欢

Salt and ice particles cannot be distinguished

Open source summer interview | "after 00" PMC member Bai Zeping

运筹学基础【一】 之 导论

Actual combat | record an attack and defense drill management

Style transfer -- CCPL: contrast coherence preserving loss for versatile style transfer
![[ CTF 学习 ] CTF 中的隐写集合 —— 图片隐写术](/img/32/2da78bd5866cfab9ee64dfcb1c1204.png)
[ CTF 学习 ] CTF 中的隐写集合 —— 图片隐写术

【基于stm32f103的SHT30温湿度显示】

I didn't expect Mysql to ask these questions

ES6 -- Methods and extensions of array objects, traversal of arrays, and extension methods of strings

1. If function of Excel
随机推荐
Basic knowledge of scratch crawler framework
Summary of UPR optimization suggestions of unity
Construction of Seata multilingual system
Mit.js: small event publishing and subscription library
After watching the latest interview with big manufacturers, these six JVM interview questions were asked
The strongest JVM in the whole network is coming!
etcd学习
Metinfo function public function getcity() error: XXX function no permission load!!!
In the Internet of things market, Bosch sensor has launched a number of new solutions
很多时候都是概率
MCU experiment record
Token value replacement of burpsuite blasting
Thinking from the perspective of Aya
QT download installation tutorial
开源之夏专访|“00 后” PMC member 白泽平
Getting started with scratch
今天很重要
Introduction to fundamentals of operations research [1]
Sony announced the closure of Beijing mobile phone factory! The production line will be moved to Thailand, and the cost can be reduced by half!
Web: compiling big refactoring from 10 to 1