-
Notifications
You must be signed in to change notification settings - Fork 1
/
544 - Heavy Cargo.cpp
87 lines (66 loc) · 1.46 KB
/
544 - Heavy Cargo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include<bits/stdc++.h>
using namespace std;
int cn = 0;
class obj{
public :
int u,cost;
obj(int a ,int x){
u = a , cost = x;
}
};
class Compare{
public :
bool operator() (obj &x , obj &y){
return x.cost < y.cost ;
}
};
void solve(int city , int road){
map < string , int > code;
vector <int> parrent(city+1);
bool notvisited[city+5];
memset(notvisited,1,sizeof(notvisited));
priority_queue<obj,vector<obj>, Compare> pq;
vector < obj > graph[city + 10];
int assign = 1;
for(int i = 0 ; i < road ; i++){
string s , t;
int cost ;
cin >> s >> t >> cost;
if(code.find(s) == code.end())
code[s] = assign ++;
if(code.find(t) == code.end())
code[t] = assign ++;
int a = code[s] ; int b = code[t];
obj temp(b,cost);
obj temp2(a,cost);
graph[a].emplace_back(temp);
graph[b].emplace_back(temp2);
}
string start, stop;
cin >> start >> stop;
int st = code[start] , sp = code[stop];
int mn = 0;
for(auto x : graph[st])
pq.push(x),mn=max(mn,x.cost);
while(!pq.empty()){
obj temp = pq.top();
pq.pop();
if(notvisited[temp.u]==false)
continue ;
mn = min(mn,temp.cost);
if(temp.u==sp)
break ;
notvisited[temp.u]=false;
for(auto x : graph[temp.u])
pq.push(x);
}
cout << "Scenario #"<<++cn<<endl;
cout << mn <<" tons"<< endl << endl;
}
int main(){
ios_base::sync_with_stdio(false);
int city,road;
while(cin >> city >> road && !(road==0 and city==0))
solve(city,road);
return 0;
}