Time Limit: 2 Seconds      Memory Limit: 32768 KB      Special Judge


Gensokyo is a world which exists quietly beside ours, separated by a mystical border. It is a utopia where humans and other beings such as fairies, youkai(phantoms), and gods live peacefully together. Shameimaru Aya is a crow tengu with the ability to manipulate wind who has been in Gensokyo for over 1000 years. She runs the Bunbunmaru News - a newspaper chock-full of rumors, and owns the Bunkachou - her record of interesting observations for Bunbunmaru News articles and pictures of beautiful danmaku(barrange) or cute girls living in Gensokyo. She is the biggest connoisseur of rumors about the girls of Gensokyo among the tengu. Her intelligence gathering abilities are the best in Gensokyo!

During the coming n days, Aya is planning to take many photos of m cute girls living in Gensokyo to write Bunbunmaru News daily and record at least Gx photos of girl x in total in the Bunkachou. At the k-th day, there are Ck targets, Tk1, Tk2, ..., TkCk. The number of photos of target Tki that Aya takes should be in range [Lki, Rki], if less, Aya cannot write an interesting article, if more, the girl will become angry and use her last spell card to attack Aya. What's more, Aya cannot take more than Dk photos at the k-th day. Under these constraints, the more photos, the better.

Aya is not good at solving this complex problem. So she comes to you, an earthling, for help.

Input

There are about 40 cases. Process to the end of file.

Each case begins with two integers 1 <= n <= 365, 1 <= m <= 1000. Then m integers, G1, G2, ..., Gm in range [0, 10000]. Then n days. Each day begins with two integer 1 <= C <= 100, 0 <= D <= 30000. Then C different targets. Each target is described by three integers, 0 <= T < m, 0 <= L <= R <= 100.

Output

For each case, first output the number of photos Aya can take, -1 if it's impossible to satisfy her needing. If there is a best strategy, output the number of photos of each girl Aya should take at each day on separate lines. The output must be in the same order as the input. If there are more than one best strategy, any one will be OK.

Output a blank line after each case.

Sample Input

2 3
12 12 12
3 18
0 3 9
1 3 9
2 3 9
3 18
0 3 9
1 3 9
2 3 9 2 3
12 12 12
3 18
0 3 9
1 3 9
2 3 9
3 18
0 0 3
1 3 6
2 6 9 2 3
12 12 12
3 15
0 3 9
1 3 9
2 3 9
3 21
0 0 3
1 3 6
2 6 12

Sample Output

36
6
6
6
6
6
6 36
9
6
3
3
6
9 -1

图论 网络流

复习了一波有上下界网络流的姿势。

顺便复习了一下东方的设定

题面里的罗马音居然都能看懂,是该说新标日姿势没忘光呢还是四斋蒸鹅心呢

如何求带上下界的最大流?

在求出可行流以后,删掉超级源汇,从旧源到旧汇跑网络流,把能用的残余流量都流掉,再加上原先的下界即可。

好像这道题的SPJ挂掉了,近几个月的提交结果全是Judge Internal Error

代码不保证正确,仅供参考

 /*by SilverN*/
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
using namespace std;
const int INF=0x3f3f3f3f;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
struct edge{
int v,nxt,f;
}e[mxn<<];
int hd[mxn],mct=;
inline void add_edge(int u,int v,int f){
e[++mct].v=v;e[mct].nxt=hd[u];e[mct].f=f;hd[u]=mct;return;
}
inline void insert(int u,int v,int f){
// printf("ins:%d %d %d\n",u,v,f);
add_edge(u,v,f);add_edge(v,u,);
}
int ST,ED,S,T;
int n,m;
queue<int>q;
int d[mxn];
bool BFS(){
for(int i=;i<=ED;i++)d[i]=;
q.push(ST);
d[ST]=;
while(!q.empty()){
int u=q.front();q.pop();
for(int i=hd[u];i;i=e[i].nxt){
int v=e[i].v;
if(e[i].f && !d[v]){
d[v]=d[u]+;
q.push(v);
}
}
}
return d[ED];
}
int cur[mxn];
int DFS(int u,int lim){
if(u==ED)return lim;
int f=,tmp;
for(int &i=cur[u];i;i=e[i].nxt){
int v=e[i].v;
if(e[i].f && d[v]==d[u]+ && (tmp=DFS(v,min(lim,e[i].f)))){
e[i].f-=tmp;
e[i^].f+=tmp;
lim-=tmp;
f+=tmp;
if(!lim)return f;
}
}
d[u]=;
return f;
}
int Dinic(){
int res=,flow=;
while(BFS()){
for(int i=;i<=ED;i++)cur[i]=hd[i];
while(flow=DFS(ST,INF))res+=flow;
}
return res;
}
//
int du[mxn];
int D[mxn];
int down[][];
bool vis[][];
int id[][];
void solve_MX(){
int i,j;
ST=S;ED=T;
int ans=Dinic();
for(i=;i<=n;i++){
for(j=hd[i];j;j=e[j].nxt){
int v=e[j].v;
if(v>n && v<T){
down[i][v-n]+=e[j^].f;
}
}
}
printf("%d\n",ans);
for(i=;i<=n;i++){
for(j=;j<=m;j++){
if(vis[i][j])
printf("%d\n",down[i][j]);
}
}
return;
}
void init(){
memset(hd,,sizeof hd);mct=;
memset(vis,,sizeof vis);
memset(du,,sizeof du);
return;
}
int main(){
freopen("in.txt","r",stdin);
int i,j;
while(scanf("%d%d",&n,&m)!=EOF){
init();
S=;T=n+m+;ST=T+;ED=ST+;
int u,v,w,L,R;
for(i=;i<=m;i++){
w=read();
du[i+n]-=w;
du[T]+=w;
insert(i+n,T,INF-w);
}
for(i=;i<=n;i++){
int C=read();D[i]=read();
insert(S,i,D[i]);
for(j=;j<=C;j++){
v=read()+;L=read();R=read();
du[i]-=L;
du[v+n]+=L;
down[i][v]=L;
vis[i][v]=;
insert(i,v+n,R-L);
id[i][v]=mct;
}
}
insert(T,S,INF);
int smm=;
for(i=S;i<=T;i++){
if(du[i]>)smm+=du[i],insert(ST,i,du[i]);
else insert(i,ED,-du[i]);
}
int res=Dinic();//printf("res:%d smm:%d\n",res,smm);
if(res!=smm){
puts("-1");continue;
}
else{
solve_MX();
}
}
return ;
}

ZOJ3229 Shoot the Bullet [未AC]的更多相关文章

  1. ZOJ3229 Shoot the Bullet(有源汇流量有上下界网络的最大流)

    题目大概说在n天里给m个女孩拍照,每个女孩至少要拍Gi张照片,每一天最多拍Dk张相片且都有Ck个拍照目标,每一个目标拍照的张数要在[Lki, Rki]范围内,问最多能拍几张照片. 源点-天-女孩-汇点 ...

  2. ZOJ3229 Shoot the Bullet(有源汇的上下界最大流)

    #pragma warning(disable:4996) #include <iostream> #include <cstring> #include <string ...

  3. zoj3229 Shoot the Bullet(有源汇有上下界的最大流)

    题意: 一个屌丝给m个女神拍照,计划拍照n天,每一天屌丝给给定的C个女神拍照,每天拍照数不能超过D张,而且给每个女神i拍照有数量限制[Li,Ri],对于每个女神n天的拍照总和不能少于Gi,如果有解求屌 ...

  4. ZOJ3229 Shoot the Bullet

    http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=20756 思路:就讲一下有源汇上下界最大流的做法吧!对于所有的边,就按照无源汇 ...

  5. zoj3229 Shoot the Bullet (有源汇最大流)

    题目大意:文文要给幻想乡的女♂孩子们拍照,一共n天,m个女♂孩子,每天文文至多拍D[i]张照片,每个女♂孩子总共要被文文至少拍G[i]次.在第i天,文文可以拍c[i]个女♂孩子,c[i]个女♂孩子中每 ...

  6. zoj 3229 Shoot the Bullet(无源汇上下界最大流)

    题目:Shoot the Bullet 收藏:http://www.tuicool.com/articles/QRr2Qb 把每一天看成一个点,每个女孩也看成一个点,增加源和汇s.t,源向每一天连上[ ...

  7. 九度OJ 1016 火星A + B 未AC版,整型存储不下

    #include <iostream> #include <string.h> #include <sstream> #include <math.h> ...

  8. ZOJ 3229 Shoot the Bullet [上下界最大流]

    ZOJ 3229 Shoot the Bullet 题意:此生无悔入东方 上下界最大流 spj挂掉了我也不知道对不对,把代码放这里吧以后正常了可能会评测一下 #include <iostream ...

  9. Shoot the Bullet ZOJ - 3229 有源汇有上下界的最大流

    /** zoj提交评判不了,所以不知道代码正不正确.思路是应该没问题的.如果有不对的地方,请多指教. 题目:Shoot the Bullet ZOJ - 3229 链接:https://vjudge. ...

随机推荐

  1. POJ 2229 计数DP

    dp[i]代表是数字i的最多组合数如果i是一个奇数,i的任意一个组合都包含1,所以dp[i] = dp[i-1] 如果i是一个偶数,分两种情况讨论,一种是序列中包含1,因此dp[i]=dp[i-1]一 ...

  2. 第三次寒假作业 sketch 了解

    什么是sketch? sketch 是一种基于散列的数据结构,可以在高速网络环境中,实时地存储流量特征信息,只占用较小的空间资源,并且具备在理论上可证明的估计精度与内存的平衡特性. 通过设置散列函数, ...

  3. 最长回文子串计算(fail)

    题意: 给定一个字符串s,在s中找到最长的回文子字符串.您可以假设s的最大长度为1000. 例子: 输入: “babad” 输出: “bab” 注: “aba”也是一个有效的答案. 我的答案: 想法: ...

  4. phpcms黄页,不能选择行业。解决办法

    用phpcms黄页模块,发布产品的时候.不能选择 产品分类,点开之后,啥都没有,是空的. 这个是因为:js的问题. 解决办法:将 网站根目录的 js 文件中的两个文件,更换为 官方的两个js文件.即可 ...

  5. Android------去除标题栏

    这里暂时只给出一种方法,在java代码中去除 1.继承Activity 在onCreate方法中 getWindow().setFlags(WindowManager.LayoutParams.FLA ...

  6. 【Python】Python中的列表操作

    Python的列表操作可谓是功能强大且方便(相对于Java)简单.常规的操作就不说了(这不是一个入门教程),介绍几个很有特点的例子 添加 # 追加到结尾(append) li = [1, 2, 3, ...

  7. P3808 【模板】AC自动机(简单版)

    题目背景 这是一道简单的AC自动机模板题. 用于检测正确性以及算法常数. 为了防止卡OJ,在保证正确的基础上只有两组数据,请不要恶意提交. 管理员提示:本题数据内有重复的单词,且重复单词应该计算多次, ...

  8. IntelliJ IDEA2018注册

    第一步:0.0.0.0 account.jetbrains.com及0.0.0.0 www.jetbrains.com  添加到hosts文件 第二步:进入 http://idea.lanyus.co ...

  9. SRM16 B-2(DP)

    老鼠和洞按坐标排序 f[i][j]表示前i个洞进j只老鼠的最短距离 比赛的时候强行分三类去推式子,推是推出来了,也看出来是可以用三个单调队列去优化的,但是太繁琐了,要我敲我真没办法T^T 赛后经 on ...

  10. bzoj1051: [HAOI2006]受欢迎的牛(tarjan强连通分量)

    强连通缩下点,出度为0有多个答案为0,否则答案为出度为0的强连通分量中点的个数. 发现一道tarjan模板题,顺便复习一波tarjan #include<iostream> #includ ...