Road constructions (hdu 3917 最大权闭合图)
来源:互联网 发布:加入软件免费下载 编辑:程序博客网 时间:2024/05/20 17:16
Road constructions
Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1436 Accepted Submission(s): 467
Problem Description
N cities are required to connect with each other by a new transportation system. After several rounds of bidding, we have selected M constructions companies and
decided which section is assigned to which company, the associated cost and the direction of each road.
Due to the insufficiency of national fiscal revenue and special taxation system (the tax paid by each company pays is a fixed amount and tax payment occurs at the
beginning of the construction of the project) The government wishes to complete the project in several years and collects as much tax as possible to support the public
expense
For the restrictions of construction and engineering techniques, if a company is required to start the construction, then itself and its associated companies have to
complete all the tasks they commit (if company A constructs a road
from city 1 to city 2, company B constructs a road from city 2 to city 3, company C constructs a road from city 1 to city 3, we call
companies A and B are associated and other company pairs have no such relationship, pay attention, in this example and a are not associated, in other words,’
associated' is a directed relationship).
Now the question is what the maximum income the government can obtain in the first year is?
decided which section is assigned to which company, the associated cost and the direction of each road.
Due to the insufficiency of national fiscal revenue and special taxation system (the tax paid by each company pays is a fixed amount and tax payment occurs at the
beginning of the construction of the project) The government wishes to complete the project in several years and collects as much tax as possible to support the public
expense
For the restrictions of construction and engineering techniques, if a company is required to start the construction, then itself and its associated companies have to
complete all the tasks they commit (if company A constructs a road
from city 1 to city 2, company B constructs a road from city 2 to city 3, company C constructs a road from city 1 to city 3, we call
companies A and B are associated and other company pairs have no such relationship, pay attention, in this example and a are not associated, in other words,’
associated' is a directed relationship).
Now the question is what the maximum income the government can obtain in the first year is?
Input
There are multiple cases (no more than 50).
Each test case starts with a line, which contains 2 positive integers, n and m (1<=n<=1000, 1<=m<=5000).
The next line contains m integer which means the tax of each company.
The Third line has an integer k (1<=k<=3000)which indicates the number of the roads.
Then k lines fellow, each contains 4 integers, the start of the roads, the end of the road, the company is responsible for this road and the cost of the road.
The end of the input with two zero
Each test case starts with a line, which contains 2 positive integers, n and m (1<=n<=1000, 1<=m<=5000).
The next line contains m integer which means the tax of each company.
The Third line has an integer k (1<=k<=3000)which indicates the number of the roads.
Then k lines fellow, each contains 4 integers, the start of the roads, the end of the road, the company is responsible for this road and the cost of the road.
The end of the input with two zero
Output
For each test case output the maximum income in a separate line, and if you can not get any income, please output 0.
Sample Input
4 2500 1041 2 1 102 3 1 204 3 1 301 4 2 604 2500 10051 2 1 102 3 1 204 3 1 304 3 2 101 4 2 603 11031 2 1 1002 3 1 1003 1 1 1000 0
Sample Output
4404700Hintfor second test case, if you choose company 2 responsible ways, then you must choose the path of responsible company 1, but if you choose company 1, then you do not have to choose company 2.
Source
2011 Multi-University Training Contest 8 - Host by HUST
Recommend
lcy | We have carefully selected several similar problems for you: 3657 3915 3914 3913 3918
思路:做最大权闭合图的题就是要找到有相互依赖关系的两个集合。题目中告诉了公司之间有依赖关系,那么就以公司为节点,源点和每个公司连边权为纳税,公司和会点连边权为花费,公司与公司之间有联系的连边权为INF。
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <string>#include <map>#include <stack>#include <vector>#include <set>#include <queue>#pragma comment (linker,"/STACK:102400000,102400000")#define maxn 1005#define MAXN 5005#define mod 1000000009#define INF 0x3f3f3f3f#define pi acos(-1.0)#define eps 1e-6#define lson rt<<1,l,mid#define rson rt<<1|1,mid+1,r#define FRE(i,a,b) for(i = a; i <= b; i++)#define FRL(i,a,b) for(i = a; i < b; i++)#define mem(t, v) memset ((t) , v, sizeof(t))#define sf(n) scanf("%d", &n)#define sff(a,b) scanf("%d %d", &a, &b)#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)#define pf printf#define DBG pf("Hi\n")const int MAXM = 200010;typedef long long ll;using namespace std;struct Edge{ int to,next,cap,flow;}edge[MAXM];int tol;int head[MAXN];int gap[MAXN],dep[MAXN],pre[MAXN],cur[MAXN];void init(){ tol=0; memset(head,-1,sizeof(head));}//加边,单向图三个参数,双向图四个参数void addedge(int u,int v,int w,int rw=0){ edge[tol].to=v; edge[tol].cap=w; edge[tol].next=head[u]; edge[tol].flow=0; head[u]=tol++; edge[tol].to=u; edge[tol].cap=rw; edge[tol].next=head[v]; edge[tol].flow=0; head[v]=tol++;}//输入参数:起点,终点,点的总数//点的编号没有影响,只要输入点的总数int sap(int start,int end,int N){ memset(gap,0,sizeof(gap)); memset(dep,0,sizeof(dep)); memcpy(cur,head,sizeof(head)); int u=start; pre[u]=-1; gap[0]=N; int ans=0; while (dep[start]<N) { if (u==end) { int Min=INF; for (int i=pre[u];i!=-1;i=pre[edge[i^1].to]) if (Min>edge[i].cap-edge[i].flow) Min=edge[i].cap-edge[i].flow; for (int i=pre[u];i!=-1;i=pre[edge[i^1].to]) { edge[i].flow+=Min; edge[i^1].flow-=Min; } u=start; ans+=Min; continue; } bool flag=false; int v; for (int i=cur[u];i!=-1;i=edge[i].next) { v=edge[i].to; if (edge[i].cap-edge[i].flow && dep[v]+1==dep[u]) { flag=true; cur[u]=pre[v]=i; break; } } if (flag) { u=v; continue; } int Min=N; for (int i=head[u];i!=-1;i=edge[i].next) if (edge[i].cap-edge[i].flow && dep[edge[i].to]<Min) { Min=dep[edge[i].to]; cur[u]=i; } gap[dep[u]]--; if (!gap[dep[u]]) return ans; dep[u]=Min+1; gap[dep[u]]++; if (u!=start) u=edge[pre[u]^1].to; } return ans;}struct Node{ int u,v,c,cost;}node[MAXN];int n,m,num;int cost[MAXN];int main(){// freopen("C:/Users/asus1/Desktop/IN.txt","r",stdin); int i,j,k,u,v,c,co; while (scanf("%d%d",&n,&m),(n+m)) { init(); int all=0; for (i=1;i<=m;i++) { cost[i]=0; scanf("%d",&c); addedge(0,i,c); all+=c; } scanf("%d",&k); for (i=1;i<=k;i++) { scanf("%d%d%d%d",&node[i].u,&node[i].v,&node[i].c,&node[i].cost); cost[node[i].c]+=node[i].cost; } for (i=1;i<=m;i++) addedge(i,m+1,cost[i]); for (i=1;i<=k;i++) { for (j=1;j<=k;j++) { if (i!=j) { if (node[i].c!=node[j].c&&node[i].v==node[j].u) addedge(node[i].c,node[j].c,INF); } } } printf("%d\n",all-sap(0,m+1,m+2)); } return 0;}
1 0
- 多校HDU 3917 Road constructions(最大权闭合图)
- hdu 3917 Road constructions 最大权闭合图
- 【HDU】3917 Road constructions 最大权闭合子图
- Road constructions (hdu 3917 最大权闭合图)
- HDU 3917 Road constructions(最大权闭合图)
- HDU 3917 Road constructions(最小割---最大权闭合)
- HDU3917 Road constructions 最大权闭合图
- HDU 3917 Road constructions 最小割模型最大权闭合图
- 最大权闭合图(Road constructions)hdu3917
- hdoj 3917 Road constructions 【最小割 之 最大权闭合图】
- HDU3917 Road constructions 最大权闭合图 2011 Multi-University Training Contest 8 - Host by HUST
- hdu 3917 Road constructions (最大闭合图)
- HDU 3917 Road constructions (最小割---最大权闭包)经典
- hdu 3917 (最大权闭合图)
- hdu 3917 最大权闭合图
- hdu 3917 Road constructions
- HDU 3917 Road constructions 2011 Multi-University Training Contest 8 - Host by HUST 最大权闭包
- ★ HDU 3917 最大权闭合图模型
- ZOJ Problem Set - 1151||Word Reversal
- Android中manifest中的属性们
- hdu 赛码1010 GCD
- MariaDB 数据库还原
- 配置Log4j(很详细)
- Road constructions (hdu 3917 最大权闭合图)
- 开始充电学习
- [C++]LeetCode 26: Remove Duplicates from Sorted Array(有序数组去重)
- 关于未完全Root的Android系统如何彻底ROOT
- 跨域post方式传递数据解决方案--CORS
- Linux 环境实现ping攻击
- linux ipc 进程间通信 共享内存、socket等
- android Camera照相机技术(二)定制拍照
- 三角形