Hentium Scheduling

Time Limit: 2000ms
Memory Limit: 262144KB

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

  1. [翻译] AKKA笔记- ACTORSYSTEM (配置CONFIGURATION 与调度SCHEDULING) - 4(一)

    原文在http://rerun.me/2014/10/06/akka-notes-actorsystem-in-progress/ 像我们前面看到的,我们可以用ActorSystem的actorof方 ...

  2. Spring.Scheduling.Quartz 作业的应用(定时任务和循环触发任务)

    .定时任务的实现,比如有个任务是要晚上2点10分的时候要去触发的,先定义这个任务类RskBookFilterInitDiningService.cs,这里其实有两种实现,一种是需要继承QuartzJo ...

  3. Linux Process Management && Process Scheduling Principle

    目录 . 引言 . 进程优先级 . 进程的生命周 . 进程表示 . 进程管理相关的系统调用 . 进程调度 . 完全公平调度类 . 实时调度类 . 调度器增强 . 小结 1. 引言 在多处理器系统中,可 ...

  4. HDU Machine scheduling

    Machine scheduling Time Limit : 5000/2000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) ...

  5. 配置org.springframework.scheduling.quartz.CronTriggerBean (转载)

    在项目中又用到了定时器,对于定时器的应用总是模模糊糊的,今天结合网上找到的资料与自己在项目中写的简单地在此写一下,以备需要时查阅. 一个Quartz的CronTrigger表达式分为七项子表达式,其中 ...

  6. 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 ...

  7. [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. 答案: 长期调度决定哪些进程进 ...

  8. HDU 4045 Machine scheduling (组合数学-斯特林数,组合数学-排列组合)

    Machine scheduling Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  9. UVA 607 二十二 Scheduling Lectures

    Scheduling Lectures Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submi ...

随机推荐

  1. VK Cup 2018 - Round 1 A. Primal Sport

    A. Primal Sport time limit per test 1.5 seconds memory limit per test 256 megabytes input standard i ...

  2. CF915C Permute Digits

    思路: 从左到右贪心放置数字,要注意判断这个数字能否放置在当前位. 实现: #include <bits/stdc++.h> using namespace std; typedef lo ...

  3. TCP/IP 协议、地址

    (一)TCP/IP 协议是端与端之间通信的基础,计算机网络,分组报文,协议是将信息正确传递的组成. 计算机网络: 由多个客户端,中间路由组成的网络体系,每个节点都一个ip进行唯一识别.路由是作为一个转 ...

  4. JFreeChart应用(生成折线图)

    1.jar包,jcommon.jar和jfreechart.jar,具体用哪个版本官网去down吧: 还有另外一个jar包,gnujaxp.jar,这个引入之后编译的时候会报错,应该是xsd校验的问题 ...

  5. day25-2 OSI协议和socket抽象层

    目录 OSI协议 物理层 数据链路层 以太网协议 Mac地址 广播地址 网络层 获取对方Mac地址(ARP协议) 传输层 TCP协议 UDP协议 应用层 socket抽象层 OSI协议 互联网的本质就 ...

  6. layui 前端UI框架

    1.获取点击行的索引

  7. CREATE TYPE - 定义一个新的数据类型

    SYNOPSIS CREATE TYPE name AS ( attribute_name data_type [, ... ] ) CREATE TYPE name ( INPUT = input_ ...

  8. 1434:【例题2】Best Cow Fences

    1434:[例题2]Best Cow Fences 时间限制: 1000 ms         内存限制: 65536 KB提交数: 263     通过数: 146 [题目描述] 给定一个长度为n的 ...

  9. 德尔福 XE5 安卓调试

    https://stackoverflow.com/questions/2604727/how-can-i-connect-to-android-with-adb-over-tcp?page=2&am ...

  10. PS学习一

    1.使用缩放工具时是对文档窗口进行的缩放,它只影响视图比例:而对图像的缩放则是指对图像文件本身进行的物理缩放,它会使图像的内容变大或变小. 2.分辨率是指单位长度内包含的像素点的数量,它的单位通常为像 ...