Codeforce 10065 (BFS)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.