加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Codeforces Gym 100199 B Reactor Cooling

发布时间:2020-12-15 07:33:06 所属栏目:百科 来源:网络整理
导读:Problem B. Reactor Cooling Input file: cooling.in Output file: cooling.out Time limit: 1 second The terrorist group leaded by a well known international terrorist Ben Bladen is buliding a nuclear reactor to produce plutonium for the nuclea

Problem B. Reactor Cooling Input file: cooling.in Output file:
cooling.out Time limit: 1 second The terrorist group leaded by a well
known international terrorist Ben Bladen is buliding a nuclear reactor
to produce plutonium for the nuclear bomb they are planning to create.
Being the wicked computer genius of this group,you are responsible
for developing the cooling system for the reactor. The cooling system
of the reactor consists of the number of pipes that special cooling
liquid flows by. Pipes are connected at special points,called nodes,
each pipe has the starting node and the end point. The liquid must
flow by the pipe from its start point to its end point and not in the
opposite direction. Let the nodes be numbered from 1 to N . The
cooling system must be designed so that the liquid is circulating by
the pipes and the amount of the liquid coming to each node (in the
unit of time) is equal to the amount of liquid leaving the node. That
is,if we designate the amount of liquid going by the pipe from i
-th node to j
-th as f ij,(put f ij
= 0 if there is no pipe from node i to node j ),for each i the following condition must hold: N ∑ j
=1 f ij
= N ∑ j
=1 f ji Each pipe has some finite capacity,therefore for each i and j connected by the pipe must be f ij ≤ c ij where c ij is the capacity
of the pipe. To provide sufficient cooling,the amount of the liquid
flowing by the pipe going from i
-th to j
-th nodes must be at least l ij,thus it must be f ij ≥ l ij . Given c ij and l ij for all pipes,find the amount f ij,satisfying the
conditions specified above. Input The first line of the input file
contains the number N (1 ≤ N ≤ 200) - the number of nodes and and M —
the number of pipes. The following M lines contain four integer number
each - i,j,l ij and c ij each. There is at most one pipe
connecting any two nodes and 0 ≤ l ij ≤ c ij ≤ 10 5 for all pipes. No
pipe connects a node to itself. If there is a pipe from i
-th node to j
-th,there is no pipe from j
-th node to i
-th. Output On the first line of the output file print YES if there is the way to carry out reactor cooling and NO if there is none. In the
first case M integers must follow,k
-th number being the amount of liquid flowing by the k
-th pipe. Pipes are numbered as they are given in the input file.

对于每条边 u?>v:[b,c] ,先强制流满 b ,也就是剩下 c?b ,然后连 s?>v:b u?>t:b 。跑 s?>t 最大流,如果满流,代表存在别的流量满足 x?>u:b v?>y:b ,而且撤去 s t 之后这些流量多出来无法平衡,正好填满 u?>v:b

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int s=205,t=206,oo=0x3f3f3f3f;
int fir[210],ne[100010],to[100010],w[100010],ws[210],wt[210],low[100010],up[100010],que[210],dep[210],n,m,num;
void add(int u,int v,int x)
{
    num++;
    ne[num*2]=fir[u];
    fir[u]=num*2;
    to[num*2]=v;
    w[num*2]=x;
    ne[num*2+1]=fir[v];
    fir[v]=num*2+1;
    to[num*2+1]=u;
    w[num*2+1]=0;
}
bool bfs()
{
    int hd=1,tl=1,u,v;
    que[1]=s;
    memset(dep,0,sizeof(dep));
    dep[s]=1;
    while (hd<=tl)
    {
        u=que[hd++];
        for (int i=fir[u];i;i=ne[i])
            if (w[i]&&!dep[v=to[i]])
            {
                dep[v]=dep[u]+1;
                que[++tl]=v;
            }
    }
    return dep[t];
}
int dfs(int u,int lim)
{
    int v,ret=0,x;
    if (u==t) return lim;
    for (int i=fir[u];i&&ret<lim;i=ne[i])
        if (w[i]&&dep[v=to[i]]==dep[u]+1)
        {
            x=dfs(v,min(w[i],lim-ret));
            ret+=x;
            w[i]-=x;
            w[i^1]+=x;
        }
    if (!ret) dep[u]=0;
    return ret;
}
void check()
{
    for (int i=1;i<=t;i++)
        for (int j=fir[i];j;j=ne[j])
            if (w[j]) printf("%d:%d->%d:%dn",i,to[j],w[j]);
}
int main()
{
    freopen("cooling.in","r",stdin);
    freopen("cooling.out","w",stdout);
    int u,v,sum=0,ans=0;
    scanf("%d%d",&n,&m);
    for (int i=1;i<=m;i++)
    {
        scanf("%d%d%d%d",&u,&v,&low[i],&up[i]);
        ws[v]+=low[i];
        wt[u]+=low[i];
        sum+=low[i];
        add(u,up[i]-low[i]);
    }
    for (int i=1;i<=n;i++)
    {
        add(s,ws[i]);
        add(i,t,wt[i]);
    }
    //check();
    while (bfs()) ans+=dfs(s,oo);
    //check();
    if (ans==sum)
    {
        printf("YESn");
        for (int i=1;i<=m;i++) printf("%dn",up[i]-w[i*2]);
    }
    else printf("NOn");
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读