题目链接:传送门
一道纯纯的码农题
当然也是也要动脑子的
不然没有思路
前置知识:树链剖分、tarjan、圆方树、STL的灵活运用
题目要求两点之间路径上的最小权值,带修改
这个修改就十分恶心了
对于这个图中的每一个环,建一个方点
权值为这个环中所有点的最小权值
树剖ask的时候如果x和y的lca是方点,还要对x的父亲的权值再取一个min
因为它没有被统计过
对于修改
如果这个点不是根,更新它和它的父亲,同时在线段树中修改
否则只修改自身
对于方点的最小值用multiset来维护可是multiset那块真的不会实现啊就去抄了一个
/**
* @Date: 2019-03-14T16:52:51+08:00
* @Last modified time: 2019-03-14T16:55:41+08:00
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <algorithm>
#include <climits>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define
#define
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
int n, m, kk, a, b, c, ans, val[A], fa[A], dfn[A], top[A], siz[A], son[A], pre[A], dep[A];
int tdfn[A], kn, cnt, vis[A], low[A], sta[A], tp, cntt;
namespace Seg {
struct node {
int l, r, minn;
}tree[A];
void build(int k, int l, int r) {
tree[k].l = l; tree[k].r = r;
if (l == r) {
tree[k].minn = val[pre[l]];
return;
}
int m = (l + r) >> 1;
build(k << 1, l, m);
build(k << 1 | 1, m + 1, r);
tree[k].minn = min(tree[k << 1].minn, tree[k << 1 | 1].minn);
}
void change(int k) {
if (tree[k].l == tree[k].r) {
tree[k].minn = c;
return;
}
int m = (tree[k].l + tree[k].r) >> 1;
if (a <= m) change(k << 1);
else change(k << 1 | 1);
tree[k].minn = min(tree[k << 1].minn, tree[k << 1 | 1].minn);
}
void ask(int k) {
if (tree[k].l >= a and tree[k].r <= b) {
ans = min(ans, tree[k].minn);
return;
}
int m = (tree[k].l + tree[k].r) >> 1;
if (a <= m) ask(k << 1);
if (b > m) ask(k << 1 | 1);
}
}
multiset<int> v[A];
namespace Cut {
struct node {
int next, to;
}e[A];
int head[A], num;
void add(int fr, int to) {
e[++num].next = head[fr];
e[num].to = to;
head[fr] = num;
}
void prepare(int fr) {
siz[fr] = 1;
for (int i = head[fr]; i; i = e[i].next) {
int ca = e[i].to;
if (ca == fa[fr]) continue;
fa[ca] = fr;
dep[ca] = dep[fr] + 1;
prepare(ca);
siz[fr] += siz[ca];
if (siz[ca] > siz[son[fr]]) son[fr] = ca;
}
}
void dfs(int fr, int tp) {
dfn[fr] = ++cntt, pre[cntt] = fr, top[fr] = tp;
if (!son[fr]) return;
dfs(son[fr], tp);
for (int i = head[fr]; i; i = e[i].next) {
int ca = e[i].to;
if (ca == fa[fr] or ca == son[fr]) continue;
dfs(ca, ca);
}
}
int ask(int x, int y, int minn = inf) {
while (top[x] != top[y]) {
if (dep[top[x]] < dep[top[y]]) swap(x, y);
a = dfn[top[x]], b = dfn[x], ans = inf, Seg::ask(1);
minn = min(minn, ans); x = fa[top[x]];
}
if (dep[x] > dep[y]) swap(x, y);
a = dfn[x], b = dfn[y], ans = inf, Seg::ask(1);
minn = min(minn, ans);
if (x > n) minn = min(minn, val[fa[x]]);
return minn;
}
}
namespace normal {
struct node {
int next, to;
}e[A];
int head[A], num;
void add(int fr, int to) {
e[++num].next = head[fr];
e[num].to = to;
head[fr] = num;
}
void tarjan(int fr, int faa) {
tdfn[fr] = low[fr] = ++cnt, sta[++tp] = fr;
for (int i = head[fr]; i; i = e[i].next) {
int ca = e[i].to;
if (ca == faa) continue;
if (!tdfn[ca]) {
tarjan(ca, fr);
low[fr] = min(low[fr], low[ca]);
if (low[ca] >= tdfn[fr]) {
int p; kn++; Cut::add(kn, fr); Cut::add(fr, kn);
do {
p = sta[tp--];
Cut::add(kn, p); Cut::add(p, kn);
}while (p != ca);
}
}
else low[fr] = min(low[fr], tdfn[ca]);
}
}
}
int main(int argc, char const *argv[]) {
cin >> n >> m >> kk; kn = n;
for (int i = 1; i <= n; i++) cin >> val[i];
while (m--) {
cin >> a >> b;
normal::add(a, b); normal::add(b, a);
}
normal::tarjan(1, 0);
Cut::prepare(1); Cut::dfs(1, 1);
for (int i = 2; i <= n; i++) v[fa[i] - n].insert(val[i]);
for (int i = n + 1; i <= kn; i++) val[i] = v[i - n].empty() ? inf : *v[i - n].begin();
Seg::build(1, 1, kn);
while (kk--) {
char opt; int aa, bb;
cin >> opt >> aa >> bb;
if (opt == 'C') {
if (aa > 1 and aa <= n) {
v[fa[aa] - n].erase(v[fa[aa] - n].find(val[aa]));
v[fa[aa] - n].insert(bb);
val[fa[aa]] = v[fa[aa] - n].empty() ? inf : *v[fa[aa] - n].begin();
a = dfn[fa[aa]], c = val[fa[aa]], Seg::change(1);
}
val[aa] = bb, a = dfn[aa], c = val[aa], Seg::change(1);
}
else cout << Cut::ask(aa, bb) << endl;
}
return 0;
}