-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path17835.cpp
103 lines (79 loc) · 1.82 KB
/
17835.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <string>
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <climits>
#include <set>
#define p(a, b) make_pair(a, b)
#define SWAP(a, b, type) do { \
type temp; \
temp = a; \
a = b; \
b = temp; \
} while (0)
#define INF 1000000000
#define endl '\n'
#define ll long long
using namespace std;
int N,M,K;
bool end_point[100001];
vector<tuple<ll,ll> > tree[100001];
bool visit[100001];
struct cmp{
bool operator()(tuple<ll,ll> a,tuple<ll,ll> b){
return get<0>(a) > get<0>(b);
}
};
void dijkstra() {
ll ans_cost=0,ans_node=0;
priority_queue< tuple<ll,ll>, vector<tuple<ll,ll> >, cmp > pq;
for(int i=1;i<=N;i++){
if(!end_point[i]) continue;
pq.push({0,i});
}
while(!pq.empty()){
ll cost = get<0>(pq.top()), cur = get<1>(pq.top()); pq.pop();
if(visit[cur]) continue;
visit[cur] = true;
if(ans_cost < cost || ans_cost == cost && ans_node > cur){
ans_cost = cost;
ans_node = cur;
}
for(int j=0;j<tree[cur].size();j++){
ll next = get<1>(tree[cur][j]), total_cost = get<0>(tree[cur][j])+cost;
if(visit[next]) continue;
pq.push({total_cost,next});
}
}
cout<<ans_node<<'\n';
cout<<ans_cost;
}
void input() {
cin>>N>>M>>K;
int s,e,c;
for(int i=0;i<M;i++){
cin>>s>>e>>c;
tree[e].push_back({c,s});
}
for(int i=0;i<K;i++){
cin>>e;
end_point[e]=true;
}
}
void init() {
}
void solution() {
dijkstra();
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
input();
solution();
return 0;
}