zoukankan      html  css  js  c++  java
  • poj3469 Dual Core CPU

    Dual Core CPU
    Time Limit: 15000MS   Memory Limit: 131072K
    Total Submissions: 24092   Accepted: 10462
    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: abw. 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

    Source

     

     

    #include<cstdio>
    #include<iostream>
    using namespace std;
    const int N=2e4+5;
    const int M=1e6+5;
    struct edge{int v,next,cap;}e[M];int tot=1,head[N];
    int n,m,S,T,dis[N],q[N];
    void add(int x,int y,int z){
        e[++tot].v=y;e[tot].cap=z;e[tot].next=head[x];head[x]=tot;
        e[++tot].v=x;e[tot].cap=0;e[tot].next=head[y];head[y]=tot;
    }
    bool bfs(){
        for(int i=S;i<=T;i++) dis[i]=-1;
        int h=0,t=1;q[t]=S;dis[S]=0;
        while(h!=t){
            int x=q[++h];
            for(int i=head[x];i;i=e[i].next){
                if(e[i].cap&&dis[e[i].v]==-1){
                    dis[e[i].v]=dis[x]+1;
                    if(e[i].v==T) return 1;
                    q[++t]=e[i].v;
                }
            }
        }
        return 0;
    }
    int dfs(int x,int f){
        if(x==T) return f;
        int used=0,t;
        for(int i=head[x];i;i=e[i].next){
            if(e[i].cap&&dis[e[i].v]==dis[x]+1){
                t=dfs(e[i].v,min(e[i].cap,f));
                e[i].cap-=t;e[i^1].cap+=t;
                used+=t;f-=t;
                if(!f) return used;
            }
        }
        if(!used) dis[x]=-1;
        return used;
    }
    int dinic(){
        int res=0;
        while(bfs()) res+=dfs(S,2e9);
        return res;
    }
    void init(){
        scanf("%d%d",&n,&m);S=0;T=n+1;
        for(int i=1,a,b;i<=n;i++) scanf("%d%d",&a,&b),add(S,i,a),add(i,T,b);
        for(int i=1,a,b,w;i<=m;i++) scanf("%d%d%d",&a,&b,&w),add(a,b,w),add(b,a,w);
        printf("%d
    ",dinic());
    }
    int main(){
        init();
        return 0;
    }
  • 相关阅读:
    E1696命令行错误: 无法打开元数据文件"platform.winmd"
    搭建集群hadoop
    搭建单节点hadoop
    搭建hadoop遇到的Q&A
    Q&A(Constantly Updating)
    基于Spark的SVM模型手写数字识别
    常见设计模式——装饰模式
    常见设计模式——策略模式
    常见设计模式——观察者模式
    常见设计模式——三种工厂模式(简单工厂、工厂方法、抽象工厂)
  • 原文地址:https://www.cnblogs.com/shenben/p/6606399.html
Copyright © 2011-2022 走看看