Harbin Polytechnic OJ 2122 Travel (map + Shortest path DIJ algorithm)

Source: Internet
Author: User

Travel
Time limit:1000 MS Memory limit:32768 K
Total Submit:18(6 users) Total Accepted:3(3 users) Rating: Special Judge: No
Description

"04.24, and Sakura to Tokyo Sky Tree, the world's warmest place on top of the sky tree.

"04.26. and Sakura to Meiji Jingu Shrine. There was a wedding held there. "

"04.25. and Sakura to Disney. Haunted House is very scary. But there are Sakura in, so not scary.

" Sakura the best. "

--Jiangnan "Dragon Clan"

painted pears and Lu Mingfei today from Disney to the sky tree, but they do not have much money, so they can save the province, they now have a map on the road between the N attractions and m attractions, each road is required to ride a certain amount, and now they turn to you, Please help them calculate the minimum amount of money required from the current location to the destination.

Input

There are more than one set of data, the first row of each group of data has two numbers 2<=n<=30000,1<=m<=30000.

next N lines enter n place names.

The next M- line has two strings ( not exceeding the length ) and a number, representing the cost of the car between the two places.

the next line is to enter two strings representing the start and end points, respectively.

Output

an int number represents the minimum amount of money required.

The data guarantee does not exceed the int type range.

Sample Input
2 1
Disney
Tokyoskytree
Disney Tokyoskytree 1
Disney Tokyoskytree
Sample Output
1
Source

2014 Summer Training Session (July 19)

There are not many people who have seen the topic on science and technology. Let's see what it is! ~

#include <iostream> #include <sstream> #include <algorithm> #include <cstdio> #include < string.h> #include <cctype> #include <string> #include <cmath> #include <vector> #include <stack> #include <queue> #include <map> #include <set>using namespace std;const int maxn=30003; const int Inf=0x1f1f1f1f;int n,m;//tag start position string s;string e;map<string,int>cnt;//Map to node number struct edge{int from,to,    Dist Edge (int u,int v,int D): From (U), to (v), Dist (d) {}};vector<edge>edges;//node information for storage edge vector<int>g[maxn];//   adjacency table bool DONE[MAXN];    Mark whether to interview int D[MAXN];    Distance array struct Heapnode//for precedence queue own definition {int d,u;    BOOL operator < (const heapnode RHS) Const {return d > rhs.d;    } heapnode (int dd,int uu):d (DD), U (UU) {}};void init ()//initialization indispensable {for (int i=0; i<n; i++) g[i].clear (); Edges.clear ();}    void Addedge (int from,int to,int dist) {edges.push_back (Edge (from,to,dist));    int m = Edges.size (); G[from].pusH_back (m-1);}    void Dij (int s) {priority_queue

Harbin Polytechnic OJ 2122 Travel (map + Shortest path DIJ algorithm)

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.