Cod sursa(job #2978500)

Utilizator alin_simpluAlin Pop alin_simplu Data 13 februarie 2023 20:26:31
Problema Ubuntzei Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <fstream>
#include <vector>
#include <queue>
#include <climits>
using namespace std;

ifstream fin("ubuntzei.in");
ofstream fout("ubuntzei.out");

const int Inf = INT_MAX;
int n, m, k;
vector<vector<pair<int, int>>> G;
vector<int> D;

void Read(){
	fin >> n >> m >> k;
	
	int K[k];
	
	for (int i = 1; i <= k; ++i)
		fin >> K[i];
		
	D = vector<int>(n + 1, Inf);
	G = vector<vector<pair<int, int>>>(n + 1);
	
	int x, y, w;
	while (m--){
		fin >> x >> y >> w;
		G[x].emplace_back(y, w);
		G[y].emplace_back(x, w);
	}
}

void Dijkstra(int src, vector<int>& d){
	priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> Q;
	d[src] = 0;
	Q.emplace(0, src);
	
	while(!Q.empty()){
		auto[dx, x] = Q.top();
		Q.pop();
		
		if (dx > d[x]) continue;
		
		for (auto [y, w] : G[x]){
			if (d[y] > d[x] + w){
				d[y] = d[x] + w;
				Q.emplace(d[y], y);
				}
		}
	}
}

int main(){
	Read();
	Dijkstra(1, D);
	fout << D[n];
		
	return 0;
}