Pagini recente » Cod sursa (job #2948899) | Cod sursa (job #2820421) | Cod sursa (job #2087333) | Cod sursa (job #1842653) | Cod sursa (job #2175896)
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <bitset>
using namespace std;
ifstream in("ubuntzei.in");
ofstream out("ubuntzei.out");
struct Road {
int y, cost;
};
class Cmp {
public:
bool operator()(Road a, Road b) {
return a.cost > b.cost;
}
};
const int MAXN = 2005;
const int INF = 1e9 + 1;
int n, m, k, C[16], d1[MAXN], dn[MAXN], d[16][16], pos[MAXN], dp[32769][16];
bool isC[MAXN];
vector<Road> g[MAXN];
priority_queue<Road, vector<Road>, Cmp> q;
void init();
int dij(int, int*);
void dijkstra(int);
/*int solve(int x, bitset<15> &state) {
int mini = INF;
for (int i = 0; i < k; ++i) {
if (state[i] == 1) {
state[i] = 0;
int dxi = (x == n) ? dn[C[i + 1]] : d[pos[x]][i + 1];
mini = min(mini, solve(C[i + 1], state) + dxi);
state[i] = 1;
}
}
if (mini == INF) mini = d1[x];
return mini;
}*/
int main()
{
init();
dij(1, d1);
dij(n, dn);
for (int i = 1; i <= k; ++i) dijkstra(i);
// solve
for (int i = 1; i < (1 << k); ++i) {
}
return 0;
}
void dijkstra(int k) {
q.push({C[k], 0});
int dist[MAXN];
for (int i = 1; i <= n; ++i) dist[i] = INF;
while (!q.empty()) {
Road e = q.top(); q.pop();
int x = e.y;
if (dist[x] != INF) continue;
dist[x] = e.cost;
if (isC[x]) d[k][pos[x]] = dist[x];
for (Road &r : g[x]) {
if (dist[r.y] == INF) q.push({r.y, r.cost + dist[x]});
}
}
}
int dij(int node, int* d) {
// compute best distances from node to (C1, C2, ... Ck)
q.push({node, 0});
for (int i = 1; i <= n; ++i) d[i] = INF;
while (!q.empty()) {
Road e = q.top(); q.pop();
int x = e.y;
if (d[x] != INF) continue;
d[x] = e.cost;
for (Road &r : g[x]) {
if (d[r.y] == INF) q.push({r.y, r.cost + d[x]});
}
}
}
void init() {
in >> n >> m >> k;
for (int i = 1; i <= k; ++i) {
in >> C[i];
isC[C[i]] = true;
pos[C[i]] = i;
}
for (int i = 1; i <= m; ++i) {
int x, y, cost;
in >> x >> y >> cost;
g[x].push_back({y, cost});
g[y].push_back({x, cost});
}
}