# 【LOJ#3097】[SNOI2019]通信（费用流）

LOJ

## 题解

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define ll long long
#define MAX 50000
const int inf=1e9;
{
int x=0;bool t=false;char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')t=true,ch=getchar();
while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
return t?-x:x;
}
struct Line{int v,next,w,fy;}e[1000000];
int h[MAX],cnt=2;
inline void Add(int u,int v,int w,int fy)
{
e[cnt]=(Line){v,h[u],w,fy};h[u]=cnt++;
e[cnt]=(Line){u,h[v],0,-fy};h[v]=cnt++;
}
int S=0,T=0,tot;
ll dis[MAX],vis[MAX],TIM;
bool Update()
{
ll mn=1e18;
for(int u=0;u<=tot;++u)
if(vis[u]==TIM)
for(int i=h[u];i;i=e[i].next)
if(e[i].w&&vis[e[i].v]!=TIM)
mn=min(mn,dis[e[i].v]+e[i].fy-dis[u]);
if(mn>=inf)return false;
for(int u=0;u<=tot;++u)if(vis[u]==TIM)dis[u]+=mn;
return true;
}
ll Flow,Cost;
int dfs(int u,int flow)
{
if(u==T||!flow){Flow+=flow;Cost+=dis[S]*flow;return flow;}
int ret=0;vis[u]=TIM;
for(int i=h[u];i;i=e[i].next)
{
int v=e[i].v;
if(vis[v]!=TIM&&e[i].w&&dis[v]==dis[u]-e[i].fy)
{
int d=dfs(v,min(flow,e[i].w));
flow-=d;ret+=d;e[i].w-=d;e[i^1].w+=d;
if(!flow)break;
}
}
return ret;
}
void ZKW()
{
do
do
++TIM;
while(dfs(S,inf));
while(Update());
}
int n,W,a[MAX];
int p[MAX];
void Link(int l,int r)
{
if(l==r)return;int mid=(l+r)>>1;
int t=0;for(int i=l;i<=r;++i)p[++t]=a[i];
sort(&p[1],&p[t+1]);t=unique(&p[1],&p[t+1])-p-1;
for(int i=1;i<t;++i)
{
}
for(int i=l;i<=r;++i)
{
int q=lower_bound(&p[1],&p[t+1],a[i])-p;
}
tot+=t;
}
int main()
{
}