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. selenium实例学习地址

    一个完整的maven配置selenium webdriver工程实例   http://www.spasvo.com/ceshi/open/kygncsgj/Selenium/201312209580 ...

  2. libcanbus官方主页

    libcanbus canbus(CAN BUS V2.0 B)扩展格式库项目简析 注: 本文如果你已经有linux开发环境 请确保你使用本库时是tag版本号. 该库遵循的协议是SAE J1939-2 ...

  3. 详解Dialog(二)——有关列表的构建

    版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[+] 前言:这段时间真是忙啊忙啊忙,元旦三天假加了两天班,已经连续六周只放一天了,天天加班到十点多,真是有一口血吐在屏幕上的感觉了,博 ...

  4. (转)android res文件夹里面的drawable(ldpi、mdpi、hdpi、xhdpi、xxhdpi)

    android res文件夹里面的drawable(ldpi.mdpi.hdpi.xhdpi.xxhdpi) (1)drawable-hdpi里面存放高分辨率的图片,如WVGA (480x800),F ...

  5. Bone Collector(hdoj--2602--01背包)

    Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  6. package-org.springframework.ui-interface:Model.class

    ylbtech-package-org.springframework.ui-interface:Model.class 1.返回顶部 1. /* * Copyright 2002-2012 the ...

  7. HO引擎近况20150422

    这个月到现在才更新主要是想等UI模块中的一个地方攻关下来再更新,但是每天工作到很晚才回家所以一直没弄,上周日弄了一下基本上是通了! 公司的项目如我所料被砍了,又开始了一个新的项目,但是也存在许多问题, ...

  8. 4.Projects and Scenes介绍

    1.Project 一个项目是由一系列的文件(如图片.音频.几何).场景以及vzp文件组成.这些文件被导入到项目对应的文件夹中.项目外部资源在场景中被使用后,会导入项目中,除非该资源被标记为外部引用. ...

  9. ES6变量的解构赋值

    变量的解构赋值 1.数组的解构赋值 2.对象的解构赋值 3.字符串的解构赋值 4.数值和布尔值的解构赋值 5.函数参数的解构赋值 6.圆括号问题 7.用途 1.数组的解构赋值 ES6 允许写成下面这样 ...

  10. Java中从控制台输入数据的几种常用方法(转转)

    原文博客地址:https://www.cnblogs.com/SzBlog/p/5404246.html 一.使用标准输入串System.in  //System.in.read()一次只读入一个字节 ...