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;
    }
  • 相关阅读:
    Module Error (from ./node_modules/@dcloudio/vue-cli-plugin-uni/packages/vue-loader/lib/loaders/templ
    二面角的平面角求法
    异面直线所成的角
    分式函数与高考数学
    备考反思|2021年全国卷乙卷理科数学解析版
    2021年全国卷乙卷理科数学图片版
    备考反思|2021年全国卷乙卷文科数学解析版
    2021年 全国卷乙卷文科数学图片版
    数学解题的减法和加法
    三角函数的定义
  • 原文地址:https://www.cnblogs.com/shenben/p/6606399.html
Copyright © 2011-2022 走看看