HDU 4309 Seikimatsu Occult Tonneru
Seikimatsu Occult Tonneru
This problem will be judged on HDU. Original ID: 4309
64-bit integer IO format: %I64d Java class name: Main
There are N cities in Heaven Empire, where people live, with 3 kinds of directed edges connected with each other. The 1st kind of edges is one of Great Tunnels( no more than 20 tunnels) where a certain number of people can hide here; people can also go through one tunnel from one city to another. The 2nd kind of edges is the so-called Modern Road, which can only let people go through. The 3rd kind of edges is called Ancient Bridge and all the edges of this kind have different names from others, each of which is named with one of the twelve constellations( such as Libra, Leo and so on); as they were build so long time ago, they can be easily damaged by one person's pass. Well, for each bridge, you can spend a certain deal of money to fix it. Once repaired, the 3rd kind of edges can let people pass without any limitation, namely, you can use one bridge to transport countless people. As for the former two kinds of edges, people can initially go through them without any limitation.
We want to shelter the most people with the least money.
Now please tell me the largest number of people who can hide in the Tunnels and the least money we need to spend to realize our objective.
Input
The first line, two integers: N (N<=100), m (m<=1000). They stands for the number of cities and edges.
The next line, N integers, which represent the number of people in the N cities.
Then m lines, four intergers each: u, v, w, p (1<=u, v<=N, 0<=w<=50). A directed edge u to v, with p indicating the type of the edge: if it is a Tunnel then p < 0 and w means the maximum number people who can hide in the the tunnel; if p == 0 then it is a Modern Road with w means nothing; otherwise it is an Ancient Bridge with w representing the cost of fixing the bridge. We promise there are no more than one edge from u to v.
Output
Sample Input
4 4
2 1 1 0
1 2 0 0
1 3 0 0
2 4 1 -1
3 4 3 -1 4 4
2 1 1 0
1 2 0 0
1 3 3 1
2 4 1 -1
3 4 3 -1
Sample Output
4 0
4 3
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
struct arc{
int to,flow,next;
arc(int x = ,int y = ,int z = -){
to = x;
flow = y;
next = z;
}
};
arc e[maxn*],tmpe[maxn*];
int head[maxn],d[maxn],cur[maxn];
int tot,S,T,n,m,cnt,p[maxn];
pii rec[maxn*];
void add(int u,int v,int flow){
e[tot] = arc(v,flow,head[u]);
head[u] = tot++;
e[tot] = arc(u,,head[v]);
head[v] = tot++;
}
bool bfs(){
memset(d,-,sizeof(d));
queue<int>q;
d[T] = ;
q.push(T);
while(!q.empty()){
int u = q.front();
q.pop();
for(int i = head[u]; ~i; i = e[i].next){
if(e[i^].flow && d[e[i].to] == -){
d[e[i].to] = d[u] + ;
q.push(e[i].to);
}
}
}
return d[S] > -;
}
int dfs(int u,int low){
if(u == T) return low;
int tmp = ,a;
for(int &i = cur[u]; ~i; i = e[i].next){
if(e[i].flow && d[u] == d[e[i].to]+&&(a=dfs(e[i].to,min(low,e[i].flow)))){
e[i].flow -= a;
e[i^].flow += a;
low -= a;
tmp += a;
if(!low) break;
}
}
if(!tmp) d[u] = -;
return tmp;
}
int dinic(){
int ans = ;
while(bfs()){
memcpy(cur,head,sizeof(head));
ans += dfs(S,INF);
}
return ans;
}
int main() {
int u,v,w,type;
while(~scanf("%d %d",&n,&m)){
memset(head,-,sizeof(head));
S = tot = ;
T = n+m+;
for(int i = ; i <= n; ++i){
scanf("%d",&w);
add(S,i,w);
}
int o = n + ;
for(int i = cnt = ; i < m; ++i){
scanf("%d %d %d %d",&u,&v,&w,&type);
if(type == ) add(u,v,INF);
else if(type < ){
add(u,o,INF);
add(o,v,INF);
add(o++,T,w);
}else{
rec[cnt++] = make_pair(tot,w);
add(u,v,);
}
}
int st = <<cnt,ans = ,cost = INF;
memcpy(tmpe,e,sizeof(e));
for(int i = ; i < st; ++i){
int tp = ,tc = ;
memcpy(e,tmpe,sizeof(e));
for(int k = ; k < cnt; ++k){
if(i&(<<k)){
tc += rec[k].second;
e[rec[k].first].flow = INF;
}
}
tp = dinic();
if(tp > ans){
ans = tp;
cost = tc;
}else if(tp == ans && cost > tc) cost = tc;
}
if(ans == ) puts("Poor Heaven Empire");
else printf("%d %d\n",ans,cost);
}
return ;
}
HDU 4309 Seikimatsu Occult Tonneru的更多相关文章
- HDU 4309 Seikimatsu Occult Tonneru(最大流+二进制枚举)
http://acm.hdu.edu.cn/showproblem.php?pid=4309 题意: 有n个城市,每个城市有num[i]个居民,有敌人要进行地毯式轰击,居民们要逃到隧道去.现在有隧道, ...
- HDU 4309 Seikimatsu Occult Tonneru 网络流量+像缩进
主题链接:点击打开链接 意甲冠军: 题意:给出一张N(N<=100)个点,M(M<=1000条)边的有向图. 每一个点上都有一些人.每条边有4个属性(u,v,w,p). 这些边分为三种:( ...
- HDU 4309 Seikimatsu Occult Tonneru (状压 + 网络流)
题意:输入 n 个城市 m 条边,但是边有三种有向边 a b c d,第一种是 d 是 0,那么就是一条普通的路,可以通过无穷多人,如果 d < 0,那么就是隧道,这个隧道是可以藏 c 个人, ...
- Seikimatsu Occult Tonneru(网络流,状态数(建不建边)不多时,可考虑直接进行枚举
http://acm.hdu.edu.cn/showproblem.php?pid=4309 总结:边可存东西时,可新建一个点x连接u.v,x再连向汇点: #include<iostream&g ...
- HDU4309-Seikimatsu Occult Tonneru(最大流)
Seikimatsu Occult Tonneru Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- HDU 4309 Contest 1
最大流建图.开始以为旧桥有1000座,没敢用枚举,后来看看题目发现了只是十二座.枚举桥的状态没问题. 对于隧道的容量W,可以虚拟出第三个结点表示,如u->v.增加一个点p,u->p(INF ...
- hdu 4309 最大流 + DFS
题意: 给以三种有向边 (1) 隧道,可以过无数人,也可以藏c个人. (2) 路,只能过人(流量INF). (3)古桥,如果不修理可以过1个人,修理可以过无数个人,但 ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
随机推荐
- windows下安装mycat,并简单使用
使用mycat需要先安装jdk1.7以上 参考:http://www.cnblogs.com/llhhll/p/9257764.html 1从官网下载解压后目录如下(1.6版本) 下载地址:https ...
- HDU 1548 A strange lift【BFS】
题意:给出一个电梯,给出它的层数f,给出起点s,终点g,以及在每一层能够上或者下w[i]层,问至少需要按多少次按钮到达终点. 和POJ catch that cow一样,直接用了那一题的代码,发现一直 ...
- ZBrush雕刻生物小技巧
本教程主要学习如何使用ZBrush®3D图形绘制软件的工具和笔刷雕刻酷酷的生物造型,我们今天来看看在游戏.媒体和电视领域有着十几年丰富经验的3D角色艺术家Francis-Xavier Martins是 ...
- 关于wdsl
WSDL元素 WSDL元素基于XML语法描述了与服务进行交互的基本元素: Type(消息类型):数据类型定义的容器,它使用某种类型系统(如XSD). Message(消息):通信数据的抽象类型化定义, ...
- pyftpdlib 搭建ftp环境
环境搭建: pythonwindows/linuxpip install pyftpdlib (安装失败请到这里下载:https://pypi.python.org/pypi/pyftpdlib/)一 ...
- tree 核心命令参数
常用参数: -a 显示所有文件 包括隐藏文件 -d 只显示目录 -f 显示每个文件的全路径 -i 不显示树枝 常与-f一起搭配 -L 显示的层数 -F 区分哪个文件是目录 [root@ftp:/va ...
- 作为一名Android APP开发者的自我总结
每当接近年尾,最痛苦的工作无疑是写年终总结,写总结的同时不禁感叹这一年过得不容易阿.突然想起这一年也是自己开发Android APP的第一年,于是觉得应该给自己的APP来一个年终总结. 一.开发方面严 ...
- "pom.xml" could not be activated because it does not exist.
"pom.xml" could not be activated because it does not exist. 在sts中使用maven build,输入package然后 ...
- HDU4324 Triangle LOVE【拓扑排序】
Triangle LOVE Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) To ...
- UVALive 6084 Happy Camper(数学题)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...