Pagini recente » Cod sursa (job #3273280) | Cod sursa (job #228206) | Cod sursa (job #2177300) | Cod sursa (job #2663857) | Cod sursa (job #2924615)
#include <fstream>
#include <vector>
#include <queue>
using namespace std;
ifstream in ("gather.in");
ofstream out ("gather.out");
struct str{
int y, d, c;
};
/// in dijkstra, y = nod curent
const int max_size1 = 751, max_size2 = 20, INF = 1e9 + 1;
int dp[max_size1][max_size2], dt[max_size1], n, k;
vector <str> mc[max_size1];
queue <str> q;
void djk ()
{
int ct, dist;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= k; j++)
{
dp[i][j] = INF;
}
}
dp[1][1] = 0;
q.push({1, 0, 1});
while (!q.empty())
{
str nod = q.front();
q.pop();
for (auto f : mc[nod.y])
{
if (nod.c - 1 <= f.c)
{
ct = nod.c;
if (dt[f.y] == 1)
{
ct++;
}
dist = nod.d + f.d * ct;
if (dp[f.y][ct] > dist)
{
dp[f.y][ct] = dist;
q.push({f.y, dist, ct});
}
}
}
}
}
int main ()
{
int m;
in >> k >> n >> m;
for (int i = 1; i <= k; i++)
{
int x;
in >> x;
dt[x] = 1;
}
while (m--)
{
int x, y, d, c;
in >> x >> y >> d >> c;
mc[x].push_back({y, d, c});
mc[y].push_back({x, d, c});
}
djk();
int ans = INF;
for (int i = 1; i <= n; i++)
{
ans = min(ans, dp[i][k]);
}
out << ans;
in.close();
out.close();
return 0;
}