Hdu 1598 find the most comfortable road (query set + enumeration)

Source: Internet
Author: User

Hdu 1598 find the most comfortable road (query set + enumeration)
Find the most comfortable roadTime Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 4899 Accepted Submission (s): 2131



Problem Description XX has many cities that communicate with each other through a strange highway SARS (Super Air Roam Structure --- Super Air Roaming Structure, each piece of SARS imposes a fixed Speed limit on the Flycar driving. Meanwhile, XX has special requirements on Flycar's "comfort, that is, the lower the speed difference between the highest speed and the lowest speed, the more comfortable the ride. (It is understood that flycar must speed up/speed down instantly, which is painful ),
However, XX has less requirements on time. You need to find the most comfortable path between cities. (SARS is bidirectional ).

Input includes multiple test instances, each of which includes:
The first line has two positive integers n (1 The following rows are three positive integers, StartCity, EndCity, and speed. StartCity is converted to EndCity on the surface, and the speed limit is speedSARS. Speed <= 1000000
Then there is a positive integer Q (Q <11), indicating the number of pathfinding.
Next, each row in row Q has two positive integers Start and End, indicating the Start and End of the path.
Output: print a line for each route seeking. Only one non-negative integer is Output, indicating the maximum comfort speed and the lowest speed of the optimal route. If the start and end cannot be reached, the output is-1.
Sample Input

4 41 2 22 3 41 4 13 4 221 31 2

Sample Output
1

0

I don't need to talk about the meaning of the question in Chinese. I have checked the set, sorted and enumerated items. Below are some comments I have added for my understanding of the monkey code ,, 7, 22

 

# Include
 
  
# Include
  
   
# Includeusing namespace std; struct node {int SC, ec, speed;} a [1100]; int f [210]; int n, m; bool cmp (node, node B) {return. speed
   
    
= Ans) continue; merge (a [j]. SC, a [j]. ec); if (find (s) = find (e) // if the start point and the end point are connected, a [j]. speed is the maximum speed of this route {if (ans> a [j]. speed-a [I]. speed) ans = a [j]. speed-a [I]. speed ;}} return ans;} int main () {int I, t, s, e; while (~ Scanf (% d, & n, & m) {for (I = 0; I
    
     

 

 

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.