CodeForcesGym 100517H Hentium Scheduling
Hentium Scheduling
This problem will be judged on CodeForcesGym. Original ID: 100517H
64-bit integer IO format: %I64d Java class name: (Any)

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int maxn = ;
struct arc {
int to,next;
LL flow;
arc(int x = ,LL y = ,int z = -) {
to = x;
flow = y;
next = z;
}
} e[];
int head[maxn],d[maxn],cur[maxn],tot,S,T;
void add(int u,int v,LL flow) {
e[tot] = arc(v,flow,head[u]);
head[u] = tot++;
e[tot] = arc(u,,head[v]);
head[v] = tot++;
}
bool bfs() {
queue<int>q;
memset(d,-,sizeof d);
d[S] = ;
q.push(S);
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[T] > -;
}
LL dfs(int u,LL low) {
if(u == T) return low;
LL a,tmp = ;
for(int &i = cur[u]; ~i; i = e[i].next) {
if(e[i].flow && d[e[i].to] == d[u]+&&(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;
}
LL dinic(LL ret = ) {
while(bfs()) {
memcpy(cur,head,sizeof head);
ret += dfs(S,INF);
}
return ret;
}
bool vis[maxn];
void dfs(int u) {
vis[u] = true;
for(int i = head[u]; ~i; i = e[i].next)
if(e[i].flow && !vis[e[i].to]) dfs(e[i].to);
}
int main() {
#define NAME "hentium"
freopen(NAME".in","r",stdin);
freopen(NAME".out","w",stdout);
int n,a,b;
while(scanf("%d",&n),n) {
memset(head,-,sizeof head);
S = tot = ;
T = n + ;
for(int i = ; i <= n; ++i) {
scanf("%d%d",&a,&b);
add(S,i,a);
add(i,T,b);
}
for(int i = ; i <= n; ++i)
for(int j = ; j <= n; ++j) {
scanf("%d",&a);
if(a) add(i,j,a);
}
printf("%I64d\n",dinic());
memset(vis,false,sizeof vis);
dfs(S);
for(int i = ; i <= n; ++i)
printf("%d%c",vis[i]?:,i == n?'\n':' ');
}
return ;
}
CodeForcesGym 100517H Hentium Scheduling的更多相关文章
- [翻译] AKKA笔记- ACTORSYSTEM (配置CONFIGURATION 与调度SCHEDULING) - 4(一)
原文在http://rerun.me/2014/10/06/akka-notes-actorsystem-in-progress/ 像我们前面看到的,我们可以用ActorSystem的actorof方 ...
- Spring.Scheduling.Quartz 作业的应用(定时任务和循环触发任务)
.定时任务的实现,比如有个任务是要晚上2点10分的时候要去触发的,先定义这个任务类RskBookFilterInitDiningService.cs,这里其实有两种实现,一种是需要继承QuartzJo ...
- Linux Process Management && Process Scheduling Principle
目录 . 引言 . 进程优先级 . 进程的生命周 . 进程表示 . 进程管理相关的系统调用 . 进程调度 . 完全公平调度类 . 实时调度类 . 调度器增强 . 小结 1. 引言 在多处理器系统中,可 ...
- HDU Machine scheduling
Machine scheduling Time Limit : 5000/2000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) ...
- 配置org.springframework.scheduling.quartz.CronTriggerBean (转载)
在项目中又用到了定时器,对于定时器的应用总是模模糊糊的,今天结合网上找到的资料与自己在项目中写的简单地在此写一下,以备需要时查阅. 一个Quartz的CronTrigger表达式分为七项子表达式,其中 ...
- Spring4.1.0 整合quartz1.8.2 时 : class not found : org.springframework.scheduling.quartz.JobDetailBean
最近做一个 Spring4.1.0 集成 quartz1.8.2 定时器功能,一直报 class not found : org.springframework.scheduling.quartz.J ...
- [Chapter 3 Process]Practice 3.8: Describe the differences among short-term, medium-term, long-term scheduling
3.8 Describe the differences among short-term, medium-term, and longterm scheduling. 答案: 长期调度决定哪些进程进 ...
- HDU 4045 Machine scheduling (组合数学-斯特林数,组合数学-排列组合)
Machine scheduling Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- UVA 607 二十二 Scheduling Lectures
Scheduling Lectures Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submi ...
随机推荐
- QT5每日一学(一)下载与安装
一.Qt SDK的下载和安装 1.下载 Qt官网主页提供了最新版Qt的下载,不过我们更倾向于去资源下载页面(https://download.qt.io/official_release ...
- 2017 JUST Programming Contest 3.0 D. Dice Game
D. Dice Game time limit per test 1.0 s memory limit per test 256 MB input standard input output stan ...
- Python variable 作用域和初始化
Python 根据LEGB rule在不同的namespace中找变量 在def的函数中对global 变量做修改还是不推荐的,应该将其作为参数传入函数 try: do_something() cnt ...
- vijos P1629八 容斥原理
https://vijos.org/p/1629 注意lcm要用LL 先给一个样例 1 2 1 10 思路.其实这题就是问,给定一堆数,要求不能整除其任意一个的数字有多少个. 容辞 + lcm dfs ...
- 关于C# DropDownList 动态加载数据笔记
今天在处理一个导游注册的页面,其中需要填写地址以及该地址下所有旅行社,地址区级以上都是用下拉列表实现,具体地址街道等手动填写.在填写区县之后,该区县下的所有旅行社也需要动态加载. 后台代码 DataT ...
- 写给W小姐的一封信
生活 琐碎 Hallo,Preaty.对于跟人说话,我很不擅长如何开头.我不知道什么样的开头是符合我在别人心目中我应有的形象.我不知道什么样的开头符合别人预想中与我相匹配的内容.或者说什么的开头才是一 ...
- 关于jquery获取单选框value属性值为on的问题
当取单选框的value值的时候,前提是要有value这个属性,如果没有value属性那么取出来的就会为on 取value值的常见三种方式为 $("input[name='XXX']:chec ...
- Javascript数据结构之栈
作者原文:http://hawkzz.com/blog/blog/1515054561771 定义 栈是一种特殊的列表,栈内的元素只能通过列表的一端访问,这一端称为栈顶.栈被称为一种先入后出的数据结构 ...
- C#中的常量、类型推断和作用域
一.常量 常量是其值在使用过程中不会发生变化的变量.在声明和初始化变量时,在变量前面家关键字const,就可以把该变量指定为一个常量: const int a=100;//a的值将不可以改变 常量的特 ...
- js 日期时间大小比较
<body> 开始时间:<input onfocus="setday(this)" id="startTime" name="sta ...