Pagini recente » Cod sursa (job #480197) | Cod sursa (job #1657418) | IAP #2: Concurs pentru studenti | Cod sursa (job #2958147) | Cod sursa (job #3211460)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ubuntzei.in");
ofstream fout("ubuntzei.out");
const int MAX_SIZE = 10000;
const int MAX_COST = 100000;
vector<int> graph[MAX_SIZE + 1];
map<pair<int, int>, int> cost;
long long minCost[MAX_SIZE];
bool isVisited[MAX_SIZE + 1];
void dijkstra() {
priority_queue<pair<long long, long long>> q;
q.push({0, 1});
minCost[1] = 0;
while (q.empty() == 0) {
pair<long long, long long> currentNode = q.top();
q.pop();
isVisited[currentNode.second] = 1;
if (-currentNode.first > minCost[currentNode.second]) {
continue;
}
for (vector<int>::iterator it = graph[currentNode.second].begin(); it < graph[currentNode.second].end(); ++it) {
if (isVisited[*it] == 0 && -currentNode.first + cost[{currentNode.second, *it}] < minCost[*it]) {
minCost[*it] = -currentNode.first + cost[{currentNode.second, *it}];
q.push({-minCost[*it], *it});
}
}
}
}
void solve() {
int noNodes, noEdges;
fin >> noNodes >> noEdges;
int k;
fin >> k;
for (int i = 1; i <= k; ++i) {
int number;
fin >> number;
}
long long sum = 0;
for (int i = 1; i <= noEdges; ++i) {
int startNode, endNode, value;
fin >> startNode >> endNode >> value;
cost[{startNode, endNode}] = value;
cost[{endNode, startNode}] = value;
sum += cost[{startNode, endNode}];
graph[startNode].push_back(endNode);
graph[endNode].push_back(startNode);
}
for (int i = 1; i <= noNodes; ++i) {
minCost[i] = (long long)MAX_SIZE * MAX_COST + 1;
}
dijkstra();
if (k == 0) {
fout << minCost[noNodes];
} else {
fout << sum;
}
}
int main() {
solve();
return 0;
}