题意
给一个 n n n个点 m m m条边的无向图,边有边权。每次会改变一条边的边权,并询问 1 1 1到 n n n的最短路。询问之间独立。
n , m , q ≤ 200000 n,m,q\le200000 n,m,q≤200000
分析
这跟HNOI2014道路堵塞基本就是一个题。
最短路分两种情况:经过修改的边和不经过修改的边。第一种情况可以通过预处理最短路直接得出,第二种情况相当于要求删掉一条边后从 1 1 1到 n n n的最短路。
我做那个题的方法是:找到一条最短路,然后枚举删边的同时加点跑spfa,但复杂度不会证。
还有一种做法是分别建出从 1 1 1和 n n n开始的最短路树,如果不经过从 1 1 1到 n n n最短路上的某一条边,则最短路最多只会经过一条树边。
这时我们可以枚举每一条树边,考虑走它时对哪些边有贡献,这里相当于对区间取最小值。
用数据结构维护一下就好了。
代码
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#define mp std::make_pair
#define pb push_back
typedef long long LL;
typedef std::pair<LL,int> pi;
const int N=200005;
const LL inf=(LL)1e16;
int n,m,q,cnt,last[N],id[N],tot,bel1[N],bel2[N],fa1[N],fa2[N];
bool vis[N],inq[N];
LL dis1[N],dis2[N],mn[N];
struct edge{
int to,next,w;bool f;}e[N*2];
std::vector<int> e1[N],e2[N];
std::vector<LL> vec[N];
std::queue<int> que;
std::priority_queue<pi> pque;
std::multiset<LL> se;
std::multiset<LL>::iterator it;
void addedge(int u,int v,int w)
{
e[++cnt].to=v;e[cnt].w=w;e[cnt].next