UVA 1212 - Duopoly(最小割)
来源:互联网 发布:青龙取水选股公式源码 编辑:程序博客网 时间:2024/05/16 02:16
UVA 1212 - Duopoly
题目链接
题意:两个公司,每个公司都有n个开价租用一些频道,一个频道只能租给一个公司,现在要求出一个分配方案使得收益最大
思路:最小割,源点连到第一个公司,第二个公司连到汇点,容量均为价钱,然后第一个公司和第二个公司有冲突的就连一条边容量为无穷大,然后求这个图的最小割就是去掉最小多少使得图原图不会冲突了,然后用总金额减去最小割的值即可
代码:
#include <cstdio>#include <cstring>#include <queue>#include <algorithm>using namespace std;const int MAXNODE = 6005;const int MAXEDGE = 320005;typedef int Type;const Type INF = 0x3f3f3f3f;struct Edge {int u, v;Type cap, flow;Edge() {}Edge(int u, int v, Type cap, Type flow) {this->u = u;this->v = v;this->cap = cap;this->flow = flow;}};struct Dinic {int n, m, s, t;Edge edges[MAXEDGE];int first[MAXNODE];int next[MAXEDGE];bool vis[MAXNODE];Type d[MAXNODE];int cur[MAXNODE];vector<int> cut;void init(int n) {this->n = n;memset(first, -1, sizeof(first));m = 0;}void add_Edge(int u, int v, Type cap) {edges[m] = Edge(u, v, cap, 0);next[m] = first[u];first[u] = m++;edges[m] = Edge(v, u, 0, 0);next[m] = first[v];first[v] = m++;}bool bfs() {memset(vis, false, sizeof(vis));queue<int> Q;Q.push(s);d[s] = 0;vis[s] = true;while (!Q.empty()) {int u = Q.front(); Q.pop();for (int i = first[u]; i != -1; i = next[i]) {Edge& e = edges[i];if (!vis[e.v] && e.cap > e.flow) {vis[e.v] = true;d[e.v] = d[u] + 1;Q.push(e.v);}}}return vis[t];}Type dfs(int u, Type a) {if (u == t || a == 0) return a;Type flow = 0, f;for (int &i = cur[u]; i != -1; i = next[i]) {Edge& e = edges[i];if (d[u] + 1 == d[e.v] && (f = dfs(e.v, min(a, e.cap - e.flow))) > 0) {e.flow += f;edges[i^1].flow -= f;flow += f;a -= f;if (a == 0) break;}}return flow;}Type Maxflow(int s, int t) {this->s = s; this->t = t;Type flow = 0;while (bfs()) {for (int i = 0; i < n; i++)cur[i] = first[i];flow += dfs(s, INF);}return flow;}void MinCut() {cut.clear();for (int i = 0; i < m; i += 2) {if (vis[edges[i].u] && !vis[edges[i].v])cut.push_back(i);}}} gao;const int N = 300005;int T, n1, n2, vis[N];int main() {int cas = 0;scanf("%d", &T);while (T--) {int sum = 0;gao.init(0);memset(vis, 0, sizeof(vis));scanf("%d", &n1);int a, b;char c;for (int i = 1; i <= n1; i++) {scanf("%d", &a);sum += a;gao.add_Edge(0, i, a);while ((c = getchar()) != '\n') {scanf("%d", &b);vis[b] = i;}}scanf("%d", &n2);gao.n = n1 + n2 + 2;int t = n1 + n2 + 1;for (int i = n1 + 1; i <= n1 + n2; i++) {scanf("%d", &a);sum += a;gao.add_Edge(i, t, a);while ((c = getchar()) != '\n') {scanf("%d", &b);if (vis[b] != 0) gao.add_Edge(vis[b], i, INF);}}printf("Case %d:\n", ++cas);printf("%d\n", sum - gao.Maxflow(0, t));if (T) printf("\n");}return 0;}
1 0
- UVA 1212 - Duopoly(最小割)
- UVA 1212 - Duopoly(最小割)
- uva 1212 Duopoly (最小割最大流)
- (beginer)网络流(最小割最大流) UVA 1212 - Duopoly
- LA 3487 Duopoly 最小割
- UVALive - 3487 Duopoly(最小割)
- Uva-1212-Duopoly
- UVA 1515 Pool construction(最小割)
- uva 1515 Pool construction(最小割)
- uva 11248 最小割
- UVA 1515 (最小割)
- 最大流最小割 UVA
- UVa 10480 Sabotage ( 最小割最大流定理)
- UVA 11248 Frequency Hopping(最大流、最小割)
- 最大流,最小割(水塘,uva 1515)
- Uva 11146 Insurrection(最短路+最小割)
- UVa 1515 简单最小割模型
- 最小割 UVA 1515 Pool construction
- 信息化的高峰——大数据与第三次工业革命(出自九三的建言)
- Linux常用性能调优工具索引
- 关于一个int *ptr=(int *)(&a+1)问题的探讨
- poj_Biorhythms_中国剩余定理
- 搭建mysql主从服务器
- UVA 1212 - Duopoly(最小割)
- 苦逼程序员之“路”
- BASH代码Refine实例
- 何把Https网站中的安全证书导入到java中的cacerts证书库?
- [ECharts]"echarts/config" is not exists
- [ActionScript 3] 分享一个超强大的starling粒子编辑器和简单的使用教程
- leetcode-Interleaving String
- 实现根据包名判断系统中是否已安装了某个应用程序
- 网站获取城市接口