最小割经典题(两个点依附在一起的情况)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\n",ans);
}

 

转载于:https://www.cnblogs.com/mfys/p/7484692.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值