At first T, because some of the nodes have been repeatedly expanded several times, the scientific practice is topo sort, each time only 0 points into the queue, so that each node is strictly guaranteed to be extended only once.
#include <bits/stdc++.h>using namespacestd;#defineEPS 1e-9#defineBug (x) cout<< #x << ' = ' <<x<<endl;#defineMin 1e-7Const intMAXN = 1e4+4;Const intMaxe = 1e5+5;structponds{DoubleCap,now;}; typedef ponds Pants; Pants P[MAXN];intN,k;vector<int>SON[MAXN];intSt,tar,amount;int inch[Maxn];queue<int>Q;voidtopo () {P[st].now+=Amount; Q.push (St); for(inti =1; I <= N; i++)if(!inch[i] && i!=St) Q.push (i); while(Q.size ()) {intU =Q.front (); Q.pop (); Pants&p =P[u]; if(P.now-p.cap >0){ if(Son[u].size ()) {Doubleeach = (P.NOW-P.CAP)/son[u].size (); P.now=P.cap; for(inti =0; I < son[u].size (); i++){ intv =Son[u][i]; P[v].now+=Each ; if(--inch[v] = =0) Q.push (v); } }Else{P.now=P.cap; } } }}intMain () {//freopen ("In.txt", "R", stdin);scanf"%d%d",&n,&j); for(inti =1; I <= N; i++) {scanf ("%LF%LF",&p[i].cap,&P[i].now); } for(inti =0; i < K; i++){ intU,v; scanf"%d%d",&u,&v); Son[u].push_back (v); inch[v]++; } scanf ("%d%d%d",&st,&amount,&Tar);topo (); printf ("%LF", P[tar].now); return 0;}
Codeforce Gym 100685F Flood