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);
    }
  • 相关阅读:
    Apache Phoenix系列 | 从入门到精通(转载)
    Phoenix 简单介绍
    ES 调优查询亿级数据毫秒级返回!怎么做到的?--文件系统缓存
    Linux 文件系统缓存 -针对不同数据库有不同作用
    Hive 调优
    clickhouse 中文论坛
    从0到N建立高性价比的大数据平台(转载)
    ClickHouse 分布式高可用集群搭建(转载)
    Hive 模式设计
    Oracle 分区表中本地索引和全局索引的适用场景
  • 原文地址:https://www.cnblogs.com/mfys/p/7484692.html
Copyright © 2011-2022 走看看