Title: Yes, there are n puddles, with initial water, and amount of water. When the sum of water in a puddle is greater than the amount, the excess water is evenly divided between the puddles connected to the puddle, which is the direction between the puddle and the puddle.
The topic is then given the first to add Y water to the X puddle, and finally to query how much water is present in the Z Puddle.
Very well understood, mainly is the implementation of BFS.
1#include <cstdio>2#include <vector>3#include <iostream>4#include <cstring>5#include <queue>6#include <cmath>7 using namespacestd;8typedefLong Longll;9 #defineMAXN 1000000Ten One intNumber of n,k,x,y,z;//puddles, number of connections, initial water puddle number, initial added water, query puddle number APair <Double,Double>a[maxn];//amount of water and initial volume of water stored in puddles -Vector <int>e[maxn];//stored in puddles I connected puddles -Queue <int>Q; the intVIS[MAXN]; - - - voidBFS () + { - while(!q.empty ()) + { A intcut=Q.front (); Q.pop (); atvis[cut]=0; - - if(cut==z)return ; - intSize=e[cut].size (); - DoubleAdd= (A[cut].first-a[cut].second)/(Double) Size; - ina[cut].first=A[cut].second; - for(intI=0; i<size;i++) to { + intv=E[cut][i]; -a[v].first+=add; the if(A[v].first > A[v].second &&!)Vis[v]) { * Q.push (v); $vis[v]=1;Panax Notoginseng } - } the } + } A intMain () the { +scanf ("%d%d",&n,&k); - for(intI=1; i<=n;i++) scanf ("%LF%LF",&a[i].second,&A[i].first); $ $ for(intI=1; i<=k;i++) - { - intV,u; thescanf ("%d%d",&v,&u); - e[v].push_back (u);Wuyi } the -scanf (" %d%d%d",&x,&y,&z); Wua[x].first+= (Double) y; - About if(a[x].first>a[x].second) Q.push (x); $memset (Vis,0,sizeof(Vis)); - BFS (); - Doubleans=0; - if(A[z].first>a[z].second) ans=A[z].second; A Elseans=A[z].first; + theprintf"%lf\n", ans); - return 0; $}
The feeling of BFS is still more useful things, learning
Codeforce 10065 (BFS)