ACdream 1229 Data Transmission
Data Transmission
Problem Description
Recently one known microprocessor productioner has developed the new type of microprocessors that can be used in difficult mathematical calculations. The processor contains N so called nodes that are connected by M channels. Data organized in packets, pass from source node to target node by channels and are processed by the intermediate nodes.
Each node has its level that determines the type of work this node does. The source node has level 1 while the target node has level L. For data to be correctly processed each packet of it must pass in order all nodes with levels from 1 to L - that is, first it must be processed by the source node, after that by some node of level 2, so on, and finally by the target node.
Nodes can process as much data as they are asked to, however channels can only transmit the limited amount of data in a unit of time. For synchronization reasons, any data can only be transmitted from a node with level i to some node with level i + 1 and cannot be transmitted between nodes which levels differ by more than one or from a node of higher level to a node of lower level. Nodes are so fast that they can process data packet immediately, so as soon as it reaches the node it is ready to be transmitted to the node of the next level.
No data should stall in any node and no node can produce its own data, so each unit of time the number of packets coming to any node except source and target, must be equal to the number of packets leaving this node.
The scheme of data transmission that satisfies the conditions provided is called the data flow. Data flow is called blocking if there is no way to increase the value of the data flow just increasing the amount of data passing by some channels (however, there may be the way to increase it, decreasing the amount of data for some channels and increasing for other ones).
Input
The first line of the input file contains three integer numbers - N, M and L (2 <= N <= 1 500, 1 <= M <= 300 000, 2 <= L <= N). Let nodes be numbered from 1 to N. The second line contains N integer numbers, i-th of them is the level li of the i-th node (1 <= li <= L). Only one node has level 1, that is the source node, and only one node has level L - that is the target node.
Next M lines describe channels, each lines contains three integer numbers a, b and c - nodes connected by this channel and its capacity in packets per unit of time (1 <= a, b <= N, lb = la+1, 1 <= c <= 106).
Two nodes can be connected by at most one channel.
Output
Sample Input
6 7 4
1 2 3 4 3 2
1 2 3
2 3 3
3 4 4
1 6 4
6 3 2
5 4 3
6 5 4
Sample Output
3
3
4
4
1
3
3
Source
Manager
#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[];
int head[maxn],d[maxn],lev[maxn],_rank[maxn],in[maxn],out[maxn];
int n,m,L,S,T,hd,tl,tot,cur[maxn],q[maxn];
void myscanf(int &x){
char ch;
while((ch = getchar()) > '' || ch < '');
x = ;
x = x* + ch - '';
while((ch = getchar()) >= '' && ch <= '')
x = x* + ch - '';
}
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 cmp(const int &x,const int &y){
return lev[x] < lev[y];
}
void greedy(){
memset(in,,sizeof(in));
memset(out,,sizeof(out));
sort(_rank+,_rank+n+,cmp);
in[S] = INF;
for(int i = ; i <= n; i++){
int u = _rank[i];
for(int j = head[u]; ~j; j = e[j].next){
if(!(j&) && in[u] > out[u]){
int f = min(e[j].flow,in[u] - out[u]);
in[e[j].to] += f;
out[u] += f;
}
}
}
memset(in,,sizeof(in));
in[T] = INF;
for(int i = n; i >= ; --i){
int v = _rank[i];
for(int j = head[v]; ~j; j = e[j].next){
int u = e[j].to;
if(j& && out[u] > in[u]){
int f = min(e[j^].flow,min(out[u] - in[u],in[v]));
in[v] -= f;
in[u] += f;
e[j].flow += f;
e[j^].flow -= f;
}
}
}
}
bool bfs(){
memset(d,-,sizeof(d));
hd = tl = ;
q[tl++] = S;
d[S] = ;
while(hd < tl){
int u = q[hd++];
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[tl++] = e[i].to;
}
}
}
return d[T] > -;
}
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[e[i].to] == d[u] + && (a=dfs(e[i].to,min(low,e[i].flow)))){
tmp += a;
low -= a;
e[i].flow -= a;
e[i^].flow += a;
if(!low) break;
}
}
if(!tmp) d[u] = -;
return tmp;
}
int dinic(){
int tmp = ;
while(bfs()){
memcpy(cur,head,sizeof(head));
tmp += dfs(S,INF);
}
return tmp;
}
int main() {
int i,u,v,cap;
scanf("%d %d %d",&n,&m,&L);
memset(head,-,sizeof(head));
for(i = ; i <= n; i++){
myscanf(lev[i]);
_rank[i] = i;
if(lev[i] == ) S = i;
else if(lev[i] == L) T = i;
}
for(int i = tot = ; i < m; i++){
myscanf(u);
myscanf(v);
myscanf(cap);
add(u,v,cap);
}
greedy();
dinic();
for(int i = ; i < m; i++)
printf("%d\n",e[i<<|].flow);
return ;
}
ACdream 1229 Data Transmission的更多相关文章
- ZOJ-2364 Data Transmission 分层图阻塞流 Dinic+贪心预流
题意:给定一个分层图,即只能够在相邻层次之间流动,给定了各个顶点的层次.要求输出一个阻塞流. 分析:该题直接Dinic求最大流TLE了,网上说采用Isap也TLE,而最大流中的最高标号预流推进(HLP ...
- Toward Scalable Systems for Big Data Analytics: A Technology Tutorial (I - III)
ABSTRACT Recent technological advancement have led to a deluge of data from distinctive domains (e.g ...
- Chrysler -- CCD (Chrysler Collision Detection) Data Bus
http://articles.mopar1973man.com/general-cummins/34-engine-system/81-ccd-data-bus CCD (Chrysler Coll ...
- Efficient data transfer through zero copy
Efficient data transfer through zero copy https://www.ibm.com/developerworks/library/j-zerocopy/ Eff ...
- Buffer Data
waylau/netty-4-user-guide: Chinese translation of Netty 4.x User Guide. 中文翻译<Netty 4.x 用户指南> h ...
- Data Replication in a Multi-Cloud Environment using Hadoop & Peer-to-Peer technologies
http://fbevmware.blogspot.com/2013/12/data-replication-in-multi-cloud.html 要FQ... —————————————————— ...
- PatentTips – RDMA data transfer in a virtual environment
BACKGROUND Embodiments of this invention relate to RDMA (remote direct memory access) data transfer ...
- Indexing Sensor Data
In particular embodiments, a method includes, from an indexer in a sensor network, accessing a set o ...
- Data analysis system
A data analysis system, particularly, a system capable of efficiently analyzing big data is provided ...
随机推荐
- HDU3117-Fibonacci Numbers(矩阵高速幂+log)
题目链接 题意:斐波那契数列,当长度大于8时.要输出前四位和后四位 思路:后四位非常easy,矩阵高速幂取模,难度在于前四位的求解. 已知斐波那契数列的通项公式:f(n) = (1 / sqrt(5 ...
- 数据结构之---C++语言实现图的十字链表存储表示
近期一直忙着考研复习,非常久都没有更新博客了.今天写一篇数据结构的存储. //有向图的十字链表存储表示 //杨鑫 #include <iostream> #include <cstd ...
- 《linux 内核全然剖析》 笔记 CODE_SPACE 宏定义分析
在memory.c里面.遇到一个宏定义,例如以下: #define CODE_SPACE(addr) ((((addr)+4095)&~4095) < \ current->sta ...
- 利用“反射”动态加载R文件中的资源
前几天做一个Android下面数据库相关的应用.用ListVIew展示表中数据的时候我希望能给表中每一条记录,加一个展示的图片.但是用数据库保存图片是比较难搞的.于是就把所需图片都保存到res下的dr ...
- getLocationInWindow getLocationOnScreen getLeft , getTop, getBottom,getRight
版权声明:本文为博主原创文章,未经博主允许不得转载. 最近做项目时,发现在activity的onCreate()和onResume()方法里调用View.getLocationInWindow() 时 ...
- Possible multiple enumeration of IEnumerable
https://www.jetbrains.com/help/resharper/2016.1/PossibleMultipleEnumeration.html Consider the follow ...
- Node.js:常用工具
ylbtech-Node.js:常用工具 1.返回顶部 1. Node.js 常用工具 util 是一个Node.js 核心模块,提供常用函数的集合,用于弥补核心JavaScript 的功能 过于精简 ...
- npm run dev 出现警告
WARNING in ./node_modules/_webpack@3.10.0@webpack/buildin/global.js There are multiple modules with ...
- Redis(三)、Redis主从复制
一.主从复制 主从复制:主节点负责写数据,从节点负责读数据,从而实现读写分离,提高redis的高可用性. 让一个服务器去复制(replicate)另一个服务器,我们称呼被复制的服务器为主节点(mast ...
- LeetCode Weekly Contest 27
1. 557. Reverse Words in a String III 分割字符串,翻转. class Solution { public: string reverseWords(string ...