Seikimatsu Occult Tonneru

Time Limit: 6000ms
Memory Limit: 32768KB

This problem will be judged on HDU. Original ID: 4309
64-bit integer IO format: %I64d      Java class name: Main

 
During the world war, to avoid the upcoming Carpet-bombing from The Third Reich, people in Heaven Empire went to Great Tunnels for sheltering.
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

Multiple Cases.
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

If nobody can hide in the Tunnels, print “Poor Heaven Empire”, else print two integers: maximum number and minimum cost.

 

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的更多相关文章

  1. HDU 4309 Seikimatsu Occult Tonneru(最大流+二进制枚举)

    http://acm.hdu.edu.cn/showproblem.php?pid=4309 题意: 有n个城市,每个城市有num[i]个居民,有敌人要进行地毯式轰击,居民们要逃到隧道去.现在有隧道, ...

  2. HDU 4309 Seikimatsu Occult Tonneru 网络流量+像缩进

    主题链接:点击打开链接 意甲冠军: 题意:给出一张N(N<=100)个点,M(M<=1000条)边的有向图. 每一个点上都有一些人.每条边有4个属性(u,v,w,p). 这些边分为三种:( ...

  3. HDU 4309 Seikimatsu Occult Tonneru (状压 + 网络流)

    题意:输入 n 个城市 m 条边,但是边有三种有向边 a b  c d,第一种是 d 是 0,那么就是一条普通的路,可以通过无穷多人,如果 d < 0,那么就是隧道,这个隧道是可以藏 c 个人, ...

  4. Seikimatsu Occult Tonneru(网络流,状态数(建不建边)不多时,可考虑直接进行枚举

    http://acm.hdu.edu.cn/showproblem.php?pid=4309 总结:边可存东西时,可新建一个点x连接u.v,x再连向汇点: #include<iostream&g ...

  5. HDU4309-Seikimatsu Occult Tonneru(最大流)

    Seikimatsu Occult Tonneru Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 32768/32768 K (Ja ...

  6. HDU 4309 Contest 1

    最大流建图.开始以为旧桥有1000座,没敢用枚举,后来看看题目发现了只是十二座.枚举桥的状态没问题. 对于隧道的容量W,可以虚拟出第三个结点表示,如u->v.增加一个点p,u->p(INF ...

  7. hdu 4309 最大流 + DFS

    题意:      给以三种有向边     (1) 隧道,可以过无数人,也可以藏c个人.     (2) 路,只能过人(流量INF).     (3)古桥,如果不修理可以过1个人,修理可以过无数个人,但 ...

  8. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  9. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

随机推荐

  1. javaEE的开发模式

    1.什么是模式 模式在开发过程中总结出的“套路”,总结出的一套约定俗成的设计模式 2.javaEE经历的模式 model1模式: 技术组成:jsp+javaBean model1的弊端:随着业务复杂性 ...

  2. GatewayWorker 版本升级过程和注意点

    公司开发用到WorkerMan框架,开发RPC服务,用于拉取用户信息和协助用户注册. workman 官网:http://www.workerman.net/workerman 老版本: worker ...

  3. Ubuntu上面安装docker

    1.先用uname -r查看系统的信息 2.安装docker的命令为 sudo apt install docker.io 3.然后就能实现安装了 但是:运行docker search golang, ...

  4. Mysql 日期型,索引查询的问题

    问题: 表中,有一个日期字段WorkDate(Date YYYY-MM-DD格式),现在我把它建成了索引,在检索条件时,WorkDate='YYYY-MM-DD' 时,用EXPLAIN分析,能看到使用 ...

  5. POJ——T1860 Currency Exchange

    http://poj.org/problem?id=1860 Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 29874   ...

  6. poj-1151-Atlantis-线段树求面积并

    非常裸的线段树求面积并. 坐标须要离散化一下. #include<stdio.h> #include<iostream> #include<stdlib.h> #i ...

  7. hdu 5277 YJC counts stars

    hdu 5277 YJC counts stars 题意: 给出一个平面图,n个点,m条边,直线边与直线边之间不相交,求最大团的数目. 限制: 1 <= n <= 1000 思路: 因为平 ...

  8. Reading and writing

    A text file is a sequence of characters stored on a permanent medium like a hard drive, flash memory ...

  9. 5.QT制作编译器,可以简单支持中文编程

    学习了文件操作,那么先做一个自制的IDE吧,就是简单的读取,修改,保存文件,使用QT语言,附上github的代码:QT基本文件操作实现中文编程 截图: 运行效果

  10. Android 学习笔记:Navigation Drawer

    laylout文件: <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com ...