Skip to content

Instantly share code, notes, and snippets.

@yurahuna
Created March 26, 2017 03:55
Show Gist options
  • Save yurahuna/67aa0e077016cb1009d703e453231567 to your computer and use it in GitHub Desktop.
Save yurahuna/67aa0e077016cb1009d703e453231567 to your computer and use it in GitHub Desktop.
RUPCday3Dより. tupleやpairをこんな感じで使ってますという例
using Vertex = tuple<int, int, int>; // {i, j, k}
using State = pair<int, Vertex>;
priority_queue<State, vector<State>, greater<State>> pq; // cost, vertex
vvvi d(n, vvi(c + 1, vi(2, inf)));
d[0][v0][0] = 0;
pq.push(State(0, make_tuple(0, v0, 0)));
while (!pq.empty()) {
int cost;
Vertex vertex;
tie(cost, vertex) = pq.top(); pq.pop();
int i, j, k;
tie(i, j, k) = vertex;
if (d[i][j][k] < cost) continue;
for (const auto& e : G[i]) {
int ni = e.to;
int nj = (a * j + b) % c;
int nk = k ? 1 : (i == n - 1);
int edge_cost = e.cost * j;
if (d[ni][nj][nk] > cost + edge_cost) {
d[ni][nj][nk] = cost + edge_cost;
pq.push(State(d[ni][nj][nk], Vertex(ni, nj, nk)));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment