# CodeForces - 843D Dynamic Shortest Path

### Description

• $1 \ v$ ：求 $1$$v$ 的最短路。
• $2 \ c \ l_1 \ l_2 \cdots l_c$ ：把编号为 $l_1,l_2,\cdots ,l_c$ 的边的边权增加一。

$n,m\le 10^5,q\le 2000,w\le 10^9$

### Solution

#include<bits/stdc++.h>
using namespace std;

template <class T> void read(T &x) {
x = 0; bool flag = 0; char ch = getchar(); for (; ch < '0' || ch > '9'; ch = getchar()) flag |= ch == '-';
for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - 48; flag ? x = ~x + 1 : 0;
}

#define N 100010
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define ll long long
#define INF 0x3f3f3f3f3f3f3f3f

struct edge { int v, w, next; }e[N];
inline void add(int u, int v, int w) {
static int tot; e[++tot].v = v, e[tot].w = w, e[tot].next = head[u], head[u] = tot;
}

ll dis[N];
int dis2[N];

#define pli pair<ll, int>
priority_queue<pli, vector<pli >, greater<pli > > q;
queue<int> q2[N];
bool vis[N];

int main() {
rep(i, 1, m) {
}
q.push(pli(0, 1));
memset(dis, 0x3f, sizeof dis); dis[1] = 0;
while (!q.empty()) {
int u = q.top().second; q.pop();
if (vis[u]) continue; vis[u] = 1;
for (int i = head[u], v; i; i = e[i].next) if (dis[v = e[i].v] > dis[u] + e[i].w)
dis[v] = dis[u] + e[i].w, q.push(pli(dis[v], v));
}
while (Q--) {
if (op == 1) printf("%lld\n", dis[k] < INF ? dis[k] : -1);
else {
memset(dis2, 0x3f, sizeof dis2);
q2[0].push(1); dis2[1] = 0;
int mx = 0;
rep(i, 0, mx) while (!q2[i].empty()) {
int u = q2[i].front(); q2[i].pop();
if (dis2[u] < i) continue;
for (int j = head[u], v, t; j; j = e[j].next)
if (dis2[v = e[j].v] > (t = dis2[u] + (e[j].w + dis[u] - dis[v]))) {
dis2[v] = t;
if (t <= min(n - 1, k)) q2[t].push(v), mx = max(mx, t);
}
}
rep(i, 1, n) dis[i] = min(INF, dis[i] + dis2[i]);
}
}
return 0;
}

posted @ 2018-09-05 10:12 aziint 阅读(...) 评论(...) 编辑 收藏