CodeForcesGym 100517H Hentium Scheduling
2015-10-10 19:30
429 查看
Hentium Scheduling
Time Limit: 2000msMemory 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 = 210; struct arc { int to,next; LL flow; arc(int x = 0,LL y = 0,int z = -1) { to = x; flow = y; next = z; } } e[2000010]; 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,0,head[v]); head[v] = tot++; } bool bfs() { queue<int>q; memset(d,-1,sizeof d); d[S] = 1; 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] == -1) { d[e[i].to] = d[u] + 1; q.push(e[i].to); } } } return d[T] > -1; } LL dfs(int u,LL low) { if(u == T) return low; LL a,tmp = 0; for(int &i = cur[u]; ~i; i = e[i].next) { if(e[i].flow && d[e[i].to] == d[u]+1&&(a=dfs(e[i].to,min(low,e[i].flow)))) { e[i].flow -= a; e[i^1].flow += a; low -= a; tmp += a; if(!low) break; } } if(!tmp) d[u] = -1; return tmp; } LL dinic(LL ret = 0) { 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,-1,sizeof head); S = tot = 0; T = n + 1; for(int i = 1; i <= n; ++i) { scanf("%d%d",&a,&b); add(S,i,a); add(i,T,b); } for(int i = 1; i <= n; ++i) for(int j = 1; 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 = 1; i <= n; ++i) printf("%d%c",vis[i]?2:1,i == n?'\n':' '); } return 0; }
View Code
相关文章推荐
- 判断iframe是否加载完毕,在执行某方法
- Git教程干货集锦
- Convolutional Networks(要点)
- 第5章 TCP服务器-客服端程序例子
- iOS开发 ----- UIViewController转场动画
- pip安装使用详解
- IE11文档模式默认值改变方法
- Spring Boot实践应用开发(6)
- linux统计一个文件中特定字符的个数
- 关于内存泄漏
- SQL99标准
- 面向对象与面向过程
- EL调用普通类的静态方法(EL自定义函数)
- 直播间架构设计
- 修改Apache Benchmark源码实现请求数据随机的压力测试
- java动态代理(JDK和cglib)
- 梳理重点
- Oracle数据库的使用
- Oracle数据库的使用
- spring二级缓存的ehcache 的 配置文件