HDU4309-Seikimatsu Occult Tonneru(最大流)
Seikimatsu Occult Tonneru
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1741 Accepted Submission(s): 438
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.
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.
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
4 0
4 3
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;
const int maxn = 100+10;
const int maxm = 1000+10;
const int inf = 1<<25;
int n,m,nume;
struct edge{
int v,f,nxt;
};
struct build{
int u,v,w;
build(int u,int v,int w):u(u),v(v),w(w){}
};
vector<build> vb[3];
edge e[maxm];
int head[maxn];
int city[maxn];
void addedge(int u,int v,int c){
e[++nume].nxt = head[u];
e[nume].v = v;
e[nume].f = c;
head[u] = nume;
e[++nume].nxt = head[v];
e[nume].v = u;
e[nume].f = 0;
head[v] = nume;
}
void init(){
memset(head,0,sizeof head);
nume = 1;
} queue<int> que;
bool vis[maxn];
int dist[maxn];
int src,sink; void bfs(){
memset(dist,0,sizeof dist);
while(!que.empty()) que.pop();
vis[src] = true;
que.push(src);
while(!que.empty()){
int u = que.front();
que.pop();
for(int i = head[u]; i ; i = e[i].nxt){
if(e[i].f && !vis[e[i].v]){
que.push(e[i].v);
vis[e[i].v] = 1;
dist[e[i].v] = dist[u]+1;
}
}
}
} int dfs(int u,int delta){
if(u== sink) return delta;
else{
int ret = 0;
for(int i = head[u]; delta&&i; i = e[i].nxt){
if(e[i].f && dist[e[i].v] == dist[u]+1){
int dd = dfs(e[i].v,min(e[i].f,delta));
e[i].f -= dd;
e[i^1].f += dd;
delta -= dd;
ret += dd;
}
}
return ret;
}
} int maxflow(){
int ret = 0;
while(true){
memset(vis,0,sizeof vis);
bfs();
if(!vis[sink]) return ret;
ret += dfs(src,inf);
} }
int main(){ while(~scanf("%d%d",&n,&m)){
src = 0;
sink = n+1;
for(int i = 0; i < 3; i++) vb[i].clear();
for(int i = 1; i <= n; i++) scanf("%d",&city[i]);
bool flag = 0;
while(m--){
int a,b,c,d;
scanf("%d%d%d%d",&a,&b,&c,&d);
if(d==0){
vb[1].push_back(build(a,b,c));//现代桥
}
else if(d<0){
vb[0].push_back(build(a,b,c));//隧道
flag = 1;
}else{
vb[2].push_back(build(a,b,c));//古代桥
}
}
if(!flag){
printf("Poor Heaven Empire\n");
continue;
}
int d = vb[2].size();
int maxf = -1,minc = inf;
for(int i = 0; i < (1<<d); i++){
init();
int tc = 0;
for(int j = 0; j < d; j++){
if(i&(1<<j)){
addedge(vb[2][j].u,vb[2][j].v,inf);
tc += vb[2][j].w;
}else{
addedge(vb[2][j].u,vb[2][j].v,1);
}
}
for(int i = 1; i <= n; i++){
addedge(0,i,city[i]);
}
for(int i = 0; i < vb[1].size(); i++){
addedge(vb[1][i].u,vb[1][i].v,inf);
}
for(int i = 0; i < vb[0].size(); i++){
addedge(vb[0][i].u,vb[0][i].v,inf);
addedge(vb[0][i].u,n+1,vb[0][i].w);
}
int tm = maxflow();
if(tm > maxf){
maxf = tm;
minc = tc;
}
if(tm==maxf && minc > tc){
minc = tc;
} }
if(maxf==-1){
printf("Poor Heaven Empire\n");
}else{
printf("%d %d\n",maxf,minc);
}
}
return 0;
}
HDU4309-Seikimatsu Occult Tonneru(最大流)的更多相关文章
- HDU 4309 Seikimatsu Occult Tonneru
Seikimatsu Occult Tonneru Time Limit: 6000ms Memory Limit: 32768KB This problem will be judged on HD ...
- 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 ...
- 使用C#处理基于比特流的数据
使用C#处理基于比特流的数据 0x00 起因 最近需要处理一些基于比特流的数据,计算机处理数据一般都是以byte(8bit)为单位的,使用BinaryReader读取的数据也是如此,即使读取bool型 ...
- HTML 事件(三) 事件流与事件委托
本篇主要介绍HTML DOM中的事件流和事件委托. 其他事件文章 1. HTML 事件(一) 事件的介绍 2. HTML 事件(二) 事件的注册与注销 3. HTML 事件(三) 事件流与事件委托 4 ...
- FILE文件流的中fopen、fread、fseek、fclose的使用
FILE文件流用于对文件的快速操作,主要的操作函数有fopen.fseek.fread.fclose,在对文件结构比较清楚时使用这几个函数会比较快捷的得到文件中具体位置的数据,提取对我们有用的信息,满 ...
- java.IO输入输出流:过滤流:buffer流和data流
java.io使用了适配器模式装饰模式等设计模式来解决字符流的套接和输入输出问题. 字节流只能一次处理一个字节,为了更方便的操作数据,便加入了套接流. 问题引入:缓冲流为什么比普通的文件字节流效率高? ...
随机推荐
- 使用简单的 5 个步骤设置 Web 服务器集群
通过在多个处理器之间分担工作负载并采用多种软件恢复技术,能够提供高度可用的环境并提高环境的总体 RAS(可靠性.可用性和可服务性).可以得到的好处包括:更快地从意外中断中恢复运行,以及将意外中断对终端 ...
- 彻底搞定c指针
第一篇 变量的内存实质 一.先来理解C语言中变量的实质 要理解C指针,我认为一定要理解C中“变量”的存储实质,所以我就从“变量”这个东西开始讲起吧! 先来理解理解内存空间吧!请看下图: 内存地址→ ...
- 最短路知识点总结(Dijkstra,Floyd,SPFA,Bellman-Ford)
Dijkstra算法: 解决的问题: 带权重的有向图上单源最短路径问题.且权重都为非负值.如果采用的实现方法合适,Dijkstra运行时间要低于Bellman-Ford算法. 思路: 如果存在一条从i ...
- 传智播客成都java培训中心秀就业
传智播客成都java培训中心秀就业 2013年被称为"史上最难就业季",成都传智播客学员如何应对的呢? 成都传智播客的学员在工作经验上颇占优势,我们采用项目驱动式教学模式,具有多年开发实战经验及教学经 ...
- 关于ubuntu下qt编译显示Cannot connect creator comm socket /tmp/qt_temp.xxx/stub-socket的解决的方法
今天在ubuntu下安装了qtcreator,准备測试一下能否用.果然一測试就出问题了,简单编写后F5编译在gnome-terminal中出现 Cannot connect creator comm ...
- 程序猿的量化交易之路(29)--Cointrader之Tick实体(16)
转载需注明出处:http://blog.csdn.net/minimicall,http://cloudtrade.top Tick:什么是Tick,在交易平台中很常见,事实上就 单笔交易时某仅仅证券 ...
- 面向接口可扩展框架之“Mvc扩展框架及DI”
面向接口可扩展框架之“Mvc扩展框架及DI” 标题“Mvc扩展框架及DI”有点绕口,我也想不出好的命名,因为这个内容很杂,涉及多个模块,但在日常开发又密不可分 首先说Mvc扩展框架,该Mvc扩展就是把 ...
- iOS 如何创建单例对象
一.什么是单例? 说到单例我就想起了我的java啊 ,不禁感叹起我的大学时光,学了4年的java开发,到现在还是放弃了我的java,踏入了iOS的行列. 算了,入正轨,我现在正是铁树银花的青春美少女, ...
- ACdream 1135(MST-最小生成树边上2个值,维护第一个最小的前提下让还有一个最小)
F - MST Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitStatu ...
- 黑马程序员:Java基础总结----类加载器
黑马程序员:Java基础总结 类加载器 ASP.Net+Android+IO开发 . .Net培训 .期待与您交流! 类加载器 Java虚拟机中可以安装多个类加载器,系统默认三个主要类加载器,每个 ...