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. android学习—— context 和 getApplicationContext()

    一直看到好多应用里面,随手使用getApplicationContext(),不想说也不乐意说,今天转载一篇文章区分两者的区别: 在android中常常会遇到与context有关的内容 浅论一下con ...

  2. IO的阻塞、非阻塞、同步、异步

  3. util-判断当前年份所处的季度,并返回当前季度开始的月份

    ylbtech-funcation-util:  判断当前年份所处的季度,并返回当前季度开始的月份 判断当前年份所处的季度,并返回当前季度开始的月份. 1.A,Ylbtech.Model返回顶部 us ...

  4. excel 经验总结

    1.2007版excel表格中怎么将使用字母+数字下拉排序 比如:A201110300001怎么在excel表格中往下拉的时候变成A201110300002.A201110300003…… 方法: 因 ...

  5. 试验笔记 - Eclipse的.class反编译插件

    常用的反编译工具有: JAD Java Decompiler Download Mirror(?) http://varaneckas.com/jad/ JadClipse (较好) http://j ...

  6. MVC中的ActionResult

    ActionResult是控制器方法执行后返回的结果类型,控制器方法可以返回一个直接或间接从ActionResult抽象类继承的类型,如果返回的是非ActionResult类型,控制器将会将结果转换为 ...

  7. hdfs[命令] dfsadmin

    Usage: java DFSAdminNote: Administrative commands can only be run as the HDFS superuser. [-report] [ ...

  8. JAVA WEB SQLHelper类的封装

    在这次做项目中,我对自己最满意的就是封装了一下SQLHelper类,我对自己感到骄傲主要是 我是初学者,我刚开始不知道可以这样做,我只是想着试着去这样做了,结果真的可以,所以我 在我的模块就自己封装了 ...

  9. App Extension编程指南(iOS8/OS X v10.10)中文版

    http://www.cocoachina.com/ios/20141023/10027.html 当iOS 8.0和OS X v10.10发布后,一个全新的概念出现在我们眼前,那就是应用扩展.顾名思 ...

  10. HDU 5802 Windows 10 (贪心+dfs)

    Windows 10 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5802 Description Long long ago, there was ...