HDU 4750 Count The Pairs (and find out + two)

Source: Internet
Author: User

problem Description
With the 60th anniversary celebration of Nanjing University of Science and technology coming soon, the University sets N T Ourist spots to welcome guests. Of course, redwood forestsinchOur university and their Orychophragmus violaceus must be recommended asTop ten tourist spots, probably the best of all. Some undirected roads is made to connect pairs of tourist spots. For example, fromRedwood forests (suppose it's a) to Fountain Plaza (suppose it's B), there may exist an undirected road with its length c. By the There isM roads totally here. Accidently, these roads ' length isAn integer, and all of them is different. Some of these spots can reach directly or indirectly to Some other spots. For guests, they is travelling fromTourist spot S to tourist spot T, they can achieve some value f. According to the statistics calculated and recorded by usinchLast years, We found a strange-calculate the value f:from s to T, there may exist lots of different paths, G Uests wouldTryEvery one of them. One particular path isConsisted of some undirected roads. When they is travellinginch  ThisPath, they'llTryTo remember the value of longest roadinch  ThisPath. In the end, guests'll remember too many longest roads ' value, so he cannotCatchthem all. But, one thing which guests would keep itinchMind isThat the minimal number of all these longest values. and value F isexactly the same with the minimal number. TOM200 would recommend pairs (S, t) (Start spot, end spot points pair) to guests. P guests would come to visit our university, and every one of the them has a requirement forValue F, satisfying f>=t. Tom200 needs your help. For each requirement, how many pairs (s, T) can I offer?

Input
multiple cases, end with EOF. First line:n m n Tourist spots (1<n<=10000), spots ' index starts from 0. M undirected Roads (1<m<=500000). Next m lines,3integers, a b c from tourist spot A to tourist spot B, its length isC.0<a, B<n, C (0<c<1000000000), all C is different. Next one line,1Integer, P (0<p<=100000) It means p guests coming. Next p line, each line one integer, T (0<=T) the value t need to consider to satisfy F>=t.

Output
For each guest's requirement value T, output the number of pairs satisfying f>=t.  Notice, (1,2), (2,1) are different pairs.

Sample Input
2 10 1 231233 30 1 20 2 41 2 550 2345

Sample Output
2 2 0 6 6 4 4 0

Source ACM/ICPC Asia regional Nanjing Online

Main topic:

Give a graph, n points, M edge, each edge has a length, and not the same. Define f (i,j) to represent the minimum value of the maximum edge weight in all paths from node I to node J. There are Q queries, each asking for a T, asking F (i,j) the number of >=t.

Problem Solving Ideas:

and check set + simple dp+ two points.

Thinking, first by the edge from small to large, for each edge of the two nodes of the side is a, B, if a, B is not the same unicom block, then a unicom block midpoint set A and b unicom block midpoint set B must be E (because E ascending). It just happens to make its pathway.

Map[i] represents the number of point pairs with an edge of the weight of I as the F value.

Sum[i] Represents the total number of weights that are greater than or equal to the large edge of the I value as the sum of f worth.

For each t, in the sorted sig[i] (Benquan value that can be taken), find the smallest small mark J that is greater than or equal to it. Output SUM[J].

Attention:

Multiply 2 for the number of points to be evaluated.

1 #pragmaComment (linker, "/stack:1024000000,1024000000")2#include <iostream>3#include <cstdio>4#include <cstring>5#include <cmath>6#include <math.h>7#include <algorithm>8#include <queue>9#include <Set>Ten#include <bitset> One#include <map> A#include <vector> -#include <stdlib.h> -#include <stack> the using namespacestd; - #definePI ACOs (-1.0) - #defineMax (a) (a) > (b)? (a): (b) - #defineMin (a) (a) < (b)? (a): (b) + #definell Long Long - #defineEPS 1e-10 + #defineMOD 1000000007 A #defineN 10006 at #defineM 600000 - #defineINF 1e12 - intn,m; - structnode{ -     intx, y; -     intCost ; in }node[m]; - //////////////////////////////////////////////////// to intFa[n]; + intCnt[n]; - voidinit () { the      for(intI=0; i<n;i++){ *fa[i]=i; $cnt[i]=1;Panax Notoginseng     } - } the intFindintx) { +     returnfa[x]==x?x:fa[x]=find (Fa[x]); A } the  + ////////////////////////////////////////////////////// - BOOLCMP (Node A,node b) { $     returna.cost<B.cost; $ } - //////////////////////////////////////////// - intA[m]; the intB[m]; - intSum[m];Wuyi intMain () the { -      while(SCANF ("%d%d", &n,&m) = =2){ Wu          -          for(intI=0; i<m;i++){ Aboutscanf"%d%d%d",&node[i].x,&node[i].y,&node[i].cost); $          -         } -Sort (node,node+m,cmp); -          A          for(intI=0; i<m;i++){ +b[i]=Node[i].cost; the         } -          $Memset (A,0,sizeof(a)); the          the init (); the         intans=0; the          for(intI=0; i<m;i++){ -               introot1=find (node[i].x); in             intRoot2=find (NODE[I].Y); the             if(ROOT1==ROOT2)Continue; thefa[root1]=Root2; About             //Ans=ans+2*cnt[root1]*cnt[root2]; thea[i]=2*cnt[root1]*Cnt[root2]; thecnt[root2]+=CNT[ROOT1]; the                      +         } -          thememset (SUM,0,sizeof(sum));Bayi          for(intj=n-1; i>=0; i--){ thesum[i]=sum[i+1]+A[i]; the         } -          -         intQ; thescanf"%d",&q); the          while(q--){ the             intT; thescanf"%d",&t); -             intW=lower_bound (b,b+m,t)-b; theprintf"%d\n", Sum[w]); the         } the         94     } the     return 0; the}
View Code

HDU 4750 Count The Pairs (and find out + two)

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.