网络流-poj3469
来源:互联网 发布:蜂群算法 pid 编辑:程序博客网 时间:2024/04/29 04:34
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 extraw dollars for the data-exchange between them.
Output
Output only one integer, the minimum total cost.
Sample Input
3 11 102 1010 32 3 1000
Sample Output
13Dinic超时,去学一下SAP在做。。。下面是Dinic的代码:#include<iostream>#include<set>#include<map>#include<vector>#include<queue>#include<cmath>#include<climits>#include<cstdio>#include<string>#include<cstring>#include<algorithm>typedef long long LL;using namespace std;const int MAX_X=200010*3;const int INF=1000000000;struct edge{ int to,cost,rev;};vector<edge> G[MAX_X];int d[20010];int cur[20010];void add_edge(int u,int v,int cost){ edge a,b; a.to=v,a.cost=cost,a.rev=G[v].size(); b.to=u,b.cost=cost,b.rev=G[u].size()-1; G[u].push_back(a); G[v].push_back(b);}int bfs(int s,int t){ queue<int> q; memset(d,-1,sizeof(d)); d[s]=0; q.push(s); while(!q.empty()) { int top=q.front(); q.pop(); if(top==t) return 1; for(int i=0;i<G[top].size();i++) { if(d[G[top][i].to]<0&&G[top][i].cost>0) { d[G[top][i].to]=d[top]+1; q.push(G[top][i].to); } } } return 0;}int dfs(int now,int t,int maxn){ int res=0,f; if(now==t) return maxn; for(int &i=cur[now];i<G[now].size();i++) { if(G[now][i].cost>0&&d[now]<d[G[now][i].to]) { f=dfs(G[now][i].to,t,min(maxn-res,G[now][i].cost)); G[now][i].cost-=f; G[G[now][i].to][G[now][i].rev].cost+=f; res+=f; if(res==maxn) return maxn; } } return res;}void dinic(int s,int t){ int res=0; memset(cur,0,sizeof(cur)); while(bfs(s,t)) { res+=dfs(s,t,INF); } cout<<res<<endl;}int main(){ //freopen("in.txt","r",stdin); int N,M; int a,b,w; cin>>N>>M; int s=N,t=s+1; for(int i=0;i<N;i++) { scanf("%d%d",&a,&b); add_edge(i,t,a); add_edge(s,i,b); } for(int i=0;i<M;i++) { scanf("%d%d%d",&a,&b,&w); add_edge(a,b,w); } dinic(s,t); return 0;}
- 网络流-poj3469
- 网络流sap(模板)--poj3469
- 网络流(最小割最大流)【POJ3469】
- 【网络流之最小割模型】poj3469 BZOJ3144 UVA1212
- 【网络流之最小割模型】poj3469 BZOJ3144 UVA1212
- poj3469 Dual Core CPU 网络流 sap邻接表模板
- poj3469
- POJ3469
- POJ3469
- POJ3469
- (POJ3469)Dual Core CPU 网络流最小割,Dinic模板应用
- 最大流模板(poj3469)
- POJ3469 - 构造图..做最大流..
- POJ3469 Dual Core CPU 最大流dinic
- poj3469(最大流最小割问题)
- poj3469最大流(最大割)
- POJ3469 Dual Core CPU(最大流最小割定理)
- 最大流-最小割定理&poj3469 Dual Core CPU
- QT+VS2008 项目引入Qt专有QRC文件
- poj2502 Subway最短路
- [Python]使用csv dialect 读写数据
- 教孩子们编程 ——附相关有用的资料
- 【leetcode】Palindrome Partitioning
- 网络流-poj3469
- 2013-10-05 实验之LED灯全关,全开
- Oracle需要启动的服务总结
- 机房收费系统总结之7——存储过程
- ant 最基本的入门
- groovy-java
- linux 驱动中insmod与mknod各自的作用
- 异步(Asynchronous)机制(二)--异步消息机制以及Hadoop RPC
- Lead the bidirectional circular linked list——双向循环链表