Data Transmission

Special JudgeTime Limit: 12000/6000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others)
 

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

      Output the description of the data flow found. Output file must contain M lines, they must correspond to channels and contain the amount of data transmitted by the channel in a unit of time. Channels must be listed in the order they are specified in the input file.

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

Andrew Stankevich Contest 3

Manager

 
解题:dinic算法+贪心初始流。。。太BT的一道题目。。。
 
 #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的更多相关文章

  1. ZOJ-2364 Data Transmission 分层图阻塞流 Dinic+贪心预流

    题意:给定一个分层图,即只能够在相邻层次之间流动,给定了各个顶点的层次.要求输出一个阻塞流. 分析:该题直接Dinic求最大流TLE了,网上说采用Isap也TLE,而最大流中的最高标号预流推进(HLP ...

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

  3. Chrysler -- CCD (Chrysler Collision Detection) Data Bus

    http://articles.mopar1973man.com/general-cummins/34-engine-system/81-ccd-data-bus CCD (Chrysler Coll ...

  4. Efficient data transfer through zero copy

    Efficient data transfer through zero copy https://www.ibm.com/developerworks/library/j-zerocopy/ Eff ...

  5. Buffer Data

    waylau/netty-4-user-guide: Chinese translation of Netty 4.x User Guide. 中文翻译<Netty 4.x 用户指南> h ...

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

  7. PatentTips – RDMA data transfer in a virtual environment

    BACKGROUND Embodiments of this invention relate to RDMA (remote direct memory access) data transfer ...

  8. Indexing Sensor Data

    In particular embodiments, a method includes, from an indexer in a sensor network, accessing a set o ...

  9. Data analysis system

    A data analysis system, particularly, a system capable of efficiently analyzing big data is provided ...

随机推荐

  1. python爬虫解决百度贴吧登陆验证码问题

    作为贴吧重度用户,写了个贴吧爬虫脚本 抄了一些别人的代码.记得有个验证码解决的.可是忘了链接了,今天最终自己攻克了. 首先要让登陆须要验证码,不停地登陆就好了...度娘非常快会加上验证码大法的... ...

  2. ZOJ 1654 Place the Robots(最大匹配)

    Robert is a famous engineer. One day he was given a task by his boss. The background of the task was ...

  3. 利用LruCache载入网络图片实现图片瀑布流效果(改进版)

    PS: 2015年1月20日21:37:27 关于LoadImageAsyncTask和checkAllImageViewVisibility可能有点小bug 改动后的代码请參见升级版本号的代码 ht ...

  4. 各种编程语言功能综合简要介绍(C,C++,JAVA,PHP,PYTHON,易语言)

    各种编程语言功能综合简要介绍(C,C++,JAVA,PHP,PYTHON,易语言) 总结 a.一个语言或者一个东西能火是和这种语言进入某一子行业的契机有关.也就是说这个语言有没有解决社会急需的问题. ...

  5. 表格td内容过多时,td显示省略号,鼠标移入显示全部内容。

    转自:https://blog.csdn.net/weixin_42193908/article/details/80405014 两种方式显示: 1.title方式显示: <!DOCTYPE ...

  6. centos6.5 + Nat网络模式 +SecureCRT 的相关设置

    步骤1:先去查看子网掩码和子网ip 提示:打开后先不要关闭,后边还会使用 步骤2:查看本机名 输入: hostname 步骤3:修改本机名 vi /etc/sysconfig/network 在”Ho ...

  7. C - Valera and Fruits

    Problem description Valera loves his garden, where n fruit trees grow. This year he will enjoy a gre ...

  8. 移植最新u-boot(裁剪和修改默认参数)

    [参考]韦东山 教学笔记 ================================================== 最简单的bootloader的编写步骤: 1. 初始化硬件:关看门狗.设 ...

  9. MFC知识点总结

    一:消息1.什么是消息?消息是驱动windows系统运行的基础.从计算机的角度来看,消息就是一个整数.    (1)一个无符号整数,是消息值:    (2)消息附带的WPARAM和LPARAM类型的参 ...

  10. Thread pool引起的程序连接数据库响应慢

    数据库版本:percona-mysql 5.6.16 ​在很长一段时间,都会出现程序连接数据库,出现响应慢的情况,正常在几到几十毫秒之间,但是偶尔会出现上百毫秒的情况: 开始由于开发重新设置并调整过程 ...