๋ชจ๋ ์ ์ ์์ ๋ค์ต์คํธ๋ผ๋ฅผ ํ ๋ฒ์ฉ ๋๋ฆฐ๋ค๊ฑฐ๋, ํ๋ก์ด๋๋ฅผ ์จ์ ๊ฐ ์ ์ ์์์ ์ต๋จ ๊ฑฐ๋ฆฌ๋ฅผ ๋ชจ๋ ๊ตฌํ๋ฉด ์๊ฐ ์ด๊ณผ๋ฅผ ๋ฐ๋๋ค.
๊ฐ์์ ์ ์ ์ ํ๋ ๋ง๋ค๊ณ , ๋ฉด์ ์ฅ๊น์ง์ ๊ฑฐ๋ฆฌ๋ฅผ 0์ด๋ผ ํ์. ๊ทธ๋ฆฌ๊ณ ์ฌ๊ธฐ์ ๋ค์ต์คํธ๋ผ๋ฅผ ๋๋ฆฌ๋ฉด ๊ฐ ์ ์ ์์ ๋ฉด์ ์ฅ๊น์ง์ ์ต๋จ ๊ฑฐ๋ฆฌ๋ฅผ ๊ตฌํ ์ ์๋ค.
์๋ฐฉํฅ ๊ฐ์ ์ด ์๋์ ์ฃผ์ํ์.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m, k;
cin >> n >> m >> k;
vector<vector<pair<int, int>>> adj(n + 1); // cost, next
vector<int> mv(k);
for (int i = 0; i < m; i++) {
int a, b, c;
cin >> a >> b >> c;
// ๊ธธ์ ๋ฐ๋๋ก ๋ฃ์ด์ค๋ค
adj[b].emplace_back(c, a);
}
for (auto& x : mv) {
cin >> x;
}
vector<ll> dist(n + 1);
priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
pq;
fill(dist.begin(), dist.end(), 1e18);
// ๋ฉด์ ์ฅ๊น์ง ๊ฑฐ๋ฆฌ 0์ผ๋ก ์ค์
// ๊ธธ ๋ฐ๋๋ก ๋ฃ๊ณ ๋ชจ๋ ๋ฉด์ ์ฅ์์ ์ถ๋ฐํ๋ค๊ณ ๊ฐ์ ํ๊ณ ํ๊ธฐ
for (auto& x : mv) {
pq.emplace(0, x);
dist[x] = 0;
}
while (!pq.empty()) {
auto [cost, cur] = pq.top();
pq.pop();
if (dist[cur] < cost) continue;
for (auto& [c, n] : adj[cur]) {
if (dist[n] > cost + c) {
dist[n] = cost + c;
pq.emplace(dist[n], n);
}
}
}
ll idx = 0, d = 0;
for (int i = 1; i <= n; i++) {
if (dist[i] > d) {
d = dist[i];
idx = i;
}
}
cout << idx << '\n' << d << '\n';
return 0;
}
long long ์จ์ผํ๋ค. ๊ฑฐ๋ฆฌ์ ์ต๋๊ฐ์ด int ๋ฒ์๋ฅผ ๋์ด๊ฐ๋ค.