zoukankan      html  css  js  c++  java
  • 最小割经典题(两个点依附在一起的情况)poj3469

    Dual Core CPU
    Time Limit: 15000MS   Memory Limit: 131072K
    Total Submissions: 25099   Accepted: 10866
    Case Time Limit: 5000MS

    Description

    As more and more computers are equipped with dual core CPU, SetagLilb, the Chief Technology Officer of TinySoft Corporation, decided to update their famous product - SWODNIW.

    The routine consists of N modules, and each of them should run in a certain core. The costs for all the routines to execute on two cores has been estimated. Let's define them as Ai and Bi. Meanwhile, M pairs of modules need to do some data-exchange. If they are running on the same core, then the cost of this action can be ignored. Otherwise, some extra cost are needed. You should arrange wisely to minimize the total cost.

    Input

    There are two integers in the first line of input data, N and M (1 ≤ N ≤ 20000, 1 ≤ M ≤ 200000) .
    The next N lines, each contains two integer, Ai and Bi.
    In the following M lines, each contains three integers: a, b, w. The meaning is that if module a and module b don't execute on the same core, you should pay extra w dollars for the data-exchange between them.

    Output

    Output only one integer, the minimum total cost.

    Sample Input

    3 1
    1 10
    2 10
    10 3
    2 3 1000
    

    Sample Output

    13

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    const int N=20080;
    int head[N],tot,S,T;
    int q[N],dis[N],n,m;
    int mp[N][22];
    struct node
    {
        int next,v,w;
    } e[N*100];
    void add(int u,int v,int w)
    {
        e[tot].v=v;
        e[tot].w=w;
        e[tot].next=head[u];
        head[u]=tot++;
    }
    bool bfs()
    {
        memset(dis,-1,sizeof(dis));
        dis[S]=0;
        int l=0,r=0;
        q[r++]=S;
        while(l<r)
        {
            int u=q[l++];
            for(int i=head[u]; ~i; i=e[i].next)
            {
                int v=e[i].v;
                if(dis[v]==-1&&e[i].w>0)
                {
                    q[r++]=v;
                    dis[v]=dis[u]+1;
                    if(v==T) return true;
                }
            }
        }
        return false;
    }
    int dfs(int s,int low)
    {
        if(s==T||!low) return low;
        int ans=low,a;
        for(int i=head[s]; ~i; i=e[i].next)
        {
            if(e[i].w>0&&dis[e[i].v]==dis[s]+1&&(a=dfs(e[i].v,min(e[i].w,ans))))
            {
                e[i].w-=a;
                e[i^1].w+=a;
                ans-=a;
                if(!ans) return low;
            }
        }
        if(low==ans) dis[s]=-1;
        return low-ans;
    }
    int main()
    {
        scanf("%d%d",&n,&m);S=0,T=n+1;
        memset(head,-1,sizeof(head));
        tot=0;
        int x,y,u,v,w;
        for(int i=1;i<=n;++i) {
            scanf("%d%d",&x,&y);
            add(S,i,x);add(i,S,0);
            add(i,T,y);add(T,i,0);
        }
        for(int i=1;i<=m;++i) {
            scanf("%d%d%d",&u,&v,&w);
            add(u,v,w);
            add(v,u,w);
        }
        int ans=0;
        while(bfs()) ans+=dfs(S,99999999);
        printf("%d
    ",ans);
    }
  • 相关阅读:
    linux中你会新建复制移动删除文件或目录吗?三分钟搞懂【文件管理】
    从此英语渣渣也能看懂man手册-【linux man手册汉化安装使用教程】
    你真的会用ls命令吗?--文件管理命令(ls命令详解)
    Python算法系列—深度优先遍历算法【二叉树】
    Python算法系列-单词匹配模式【hash练习】
    abp 从4.3升级到5.4 从入门到放弃
    ABP core2.2错误笔记2,持续更新
    echart报错: Component series.XXX not exists. Load it first
    单例模式MQTT服务为什么会重复收到消息
    在ABP core中使用RabbitMq
  • 原文地址:https://www.cnblogs.com/mfys/p/7484692.html
Copyright © 2011-2022 走看看