[TOJ 3692] Emergency Rescue, toj1_2 rescue

Source: Internet
Author: User

[TOJ 3692] Emergency Rescue, toj1_2 rescue

# Include <iostream> # include <algorithm> # include <queue> using namespace std; # define INF 1e8int n, m, x = 0; double g [1005] [1005]; // Save the required time void f () {int I, a, vis [1005], num, s, minn = INF; double d [1005]; // storage time priority_queue <int, vector <int>, greater <int> v; // use the priority queue, from small to large x ++; for (I = 1; I <= n; I ++) // set the time from the initialization Start point 0 to the remaining intersections to the maximum value g [0] [I] = INF; scanf ("% d", & num, & s); // num intersection No. s number of police cars for (I = 0; I <= n; I ++) // traverse each intersection {vis [I] = 0; // each intersection has Status marked as inaccessible d [I] = INF; // the start time is the maximum value} // initialize for (I = 1; I <= s; I ++) // enter the location of each police car {scanf ("% d", & a); g [0] [a] = 0;} d [0] = 0; v. push (0); while (! V. empty () {a = v. top (); v. pop (); if (vis [a] = 1) continue; vis [a] = 0; for (I = 0; I <= n; I ++) {if (d [I]> d [a] + g [a] [I]) {d [I] = d [a] + g [a] [I]; v. push (I) ;}}cout <"Scenario" <x <":" <endl; if (minn = d [num]) cout <"Impossible. "<endl; else printf (" %. 2lf \ n ", d [num]); cout <" \ n ";}int main () {int I, j, k, s, e; double t; scanf ("% d", & n, & m, & k); // Number of n intersections m number of roads k number of incidents for (I = 0; I <= n; I ++) {for (j = 0; j <= n; j ++) g [I] [j] = INF; // save the time from intersection I to intersection j. g [I] [I] = 0; // set the time to 0} for (I = 0; I <m; I ++) {scanf ("% d % lf", & s, & e, & t ); // s start point e end point t time if (t <g [s] [e]) g [s] [e] = t;} for (I = 1; I <= k; I ++) f ();}

 

Related Article

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.