F. Flood
Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/gym/100685/problem/F

Description

We all know that King Triton doesn't like us and therefore shipwrecks, hurricanes and tsunami do happen. But being bored with the same routine all these years Triton has decided to make a spectacular flood this year.

He chose a small town in a hilly valley not far from the sea. The power of Triton is enough to pour one heavy rain on the hill. He is worried however that water will miss that chosen town due to various river basins and water flows. Triton asks you to help him help calculate the amount of water that reaches the chosen town.

There are water ponds in a hilly valley on the way to the town. Some of them are connected to each other with rivers. If some pond is overfull with water, the water begins to flow evenly to the connected ponds (or to the sea, if there are no connected ponds). Each pond contains some water initially, and the maximum pond capacity is also known. The chosen town is located on the bank of one pond — you should calculate the water level in this pond after all water flow is run out.

Input

On the first line of input integers N and K (2 ≤ N ≤ 104, 0 ≤ K ≤ 105) are given — the number of water ponds and the number of pond connections respectively.

On the next N lines of input integers Pi and Ai (0 ≤ Ai ≤ Pi ≤ 106) are given — these are the maximum ith water pond capacity and its initial water level.

On the next K lines of input integers Fj and Tj (1 ≤ Fj, Tj ≤ N, Fj ≠ Tj) are given — they denote a possible river flow connection from Fj to Tj water pond (reverse water flow is not possible). Consider water flow from a pond to be equally distributed between all possible flow connections from that pond. Triton is absolutely sure that there are no cycles in river flows between the ponds, and there are no multiple rivers between any two ponds.

On the last line of input integers X, Y and Z (1 ≤ X, Z ≤ N, 1 ≤ Y ≤ 106) are given — the water pond that receives Triton's heavy rain, the amount of water that is added to this pond and the target pond (near the chosen town) to test respectively.

Consider that excessive water flows from a water pond if and only if its capacity is full. If some pond is overfull and no water flows are defined from that pond consider that all excessive water has flown out to the sea.

Output

The first line of the output should contain a single floating-point number Lz — the final water level in the target pond when all water flow is complete. Answers with absolute or relative error less than 10 - 4 are considered correct.

Sample Input

4 4
10 10
1 0
1 0
10 0
1 2
1 3
2 4
3 4
1 5 4

Sample Output

3.0

HINT

题意

给一个有向无环无重边的图,然后从一个地方倒水,水满了就会溢出,溢出给所有相邻的点,都平均给,然后问你最后有多少水

题解

直接bfs就好了

代码

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <string>
#include <ctime>
#include <list>
typedef unsigned char byte;
#define pb push_back
#define input_fast std::ios::sync_with_stdio(false);std::cin.tie(0)
#define local freopen("in.txt","r",stdin)
#define pi acos(-1) using namespace std;
typedef pair<double , double > dl;
const int maxn = 1e4 + ;
vector<int>e[maxn];
int n , k , z ;
int dis[maxn];
char inq[maxn];
dl A[maxn];
queue<int>q;
double ans;
double dig[maxn]; void bfs()
{
while(!q.empty())
{
int cur = q.front();q.pop();
inq[cur] = ;
if (cur == z) return;
int degree = e[cur].size();
double add = (A[cur].first - A[cur].second)/((double)degree);
A[cur].first = A[cur].second;
for(int i = ; i < degree ; ++ i)
{
int v = e[cur][i];
A[v].first += add;
if (A[v].first > A[v].second && !inq[v])
{
q.push(v);
inq[v] = ;
}
}
}
} int main(int argc,char *argv[])
{
scanf("%d%d",&n,&k);
for(int i = ; i <= n ; ++ i) scanf("%lf%lf",&A[i].second,&A[i].first);
while(k--)
{
int u , v ;
scanf("%d%d",&u,&v);
e[u].pb(v);
}
int x,y;
scanf("%d%d%d",&x,&y,&z);
A[x].first += (double)y;
memset(inq,,sizeof(inq));
if (A[x].first > A[x].second) q.push(x);
bfs();
if (A[z].first > A[z].second ) ans = A[z].second;
else ans = A[z].first;
printf("%.8lf\n",ans);
return ;
}

Codeforces gym 100685 F. Flood bfs的更多相关文章

  1. Codeforces gym 100685 A. Ariel 暴力

    A. ArielTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/A Desc ...

  2. Codeforces gym 100685 E. Epic Fail of a Genie 贪心

    E. Epic Fail of a GenieTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685 ...

  3. Codeforces gym 100685 C. Cinderella 水题

    C. CinderellaTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/C ...

  4. codeforces Gym 100187F F - Doomsday 区间覆盖贪心

    F. Doomsday Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/F ...

  5. Codeforces Gym 100513F F. Ilya Muromets 线段树

    F. Ilya Muromets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/probl ...

  6. Codeforces Gym 100513F F. Ilya Muromets 水题

    F. Ilya Muromets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/probl ...

  7. Codeforces Gym 101190M Mole Tunnels - 费用流

    题目传送门 传送门 题目大意 $m$只鼹鼠有$n$个巢穴,$n - 1$条长度为$1$的通道将它们连通且第$i(i > 1)$个巢穴与第$\left\lfloor \frac{i}{2}\rig ...

  8. Codeforces Gym 101623A - 动态规划

    题目传送门 传送门 题目大意 给定一个长度为$n$的序列,要求划分成最少的段数,然后将这些段排序使得新序列单调不减. 考虑将相邻的相等的数缩成一个数. 假设没有分成了$n$段,考虑最少能够减少多少划分 ...

  9. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

随机推荐

  1. Delphi ORD

    //Char 类型与其编码值的转换:varb: Byte;c: Char;beginb := Ord('A');   {返回: 65}b := Ord(#65);   {返回: 65}b := Ord ...

  2. 图片的android:src 及android:background共存

    ---恢复内容开始--- 需求:给ImageView添加背景色 效果: 实现分析: 1.目录结构: 代码实现: 1.activity_main.xml <merge xmlns:android= ...

  3. git中reset与revert的使用

    http://alpha-blog.wanglianghome.org/2010/07/30/git-partial-rollback/ reset(版本撤回) 格式 git reset [-q] [ ...

  4. [Everyday Mathematics]20150202

    设 $f:\bbR^2\to \bbR$ 为连续函数, 且满足条件 $$\bex f(x+1,y)=f(x,y+1)=f(x,y),\quad\forall\ (x,y)\in \bbR^2. \ee ...

  5. Druid连接池简单入门

    偶尔的机会解释Druid连接池,后起之秀,但是评价不错,另外由于是阿里淘宝使用过的所以还是蛮看好的. 1.jar包依赖--Druid依赖代码 <dependency> <groupI ...

  6. 《零成本实现Web自动化测试--基于Selenium》第二章 Selenium简介和基础

    第一部分 Selenium简介 1.Selenium 组建 1.1 Selenium-IDE Selenium-IDC是开发Selenium测试案例的集成开发环境.它像FireFox插件一样的工作,支 ...

  7. 细雨学习笔记:Jmeter参数化

    目前我用到两种方式: 1)某个参数,值不常改变的,好多地方都用到:请用“用户定义的变量” 用户组,右键--添加--配置原件--用户定义的变量,在这添加. 如何使用呢?在需要用到此参数的地方这样引用: ...

  8. ldconfig报错 :libstdc++.so.6.0.18-gdb.py不是一个elf文件

    今天安装wxWidgets,输入ldconfig竟然提示 /usr/lib64/libstdc++.so.6.0.18-gdb.py 不是一个elf文件,开头魔数错误 摸不着头脑,上网搜了一下,有说是 ...

  9. 《Genesis-3D开源游戏引擎完整实例教程-2D射击游戏篇02:滚屏》

    2.滚屏 滚屏概述: 打飞机游戏场景背景设计通常很简单,因为角色敌人道具等都不与背景发生交互事件.开发者只需要根据设定的游戏类型,为游戏制作背景,模拟一个大环境即可. 滚屏原理: 材质UV动画,实现背 ...

  10. <Chapter 2>2-2-1.用户偏好模式(The User Preferences Pattern)

    在这个模块中我们要创建的应用是一个简单的钟.当一个用户访问这个网站时,这个应用会更具服务器的系统时间显示当前的时间.默认情况下,这个应用使用标准国际时间(UTC)时区显示当前时间.用户可以使用Goog ...