1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
| const int N = 200005; int w[N]; int n,m;
namespace Tree{ vector<int> g[N]; int fa[N],dep[N],siz[N],son[N],top[N],dfn[N],idx; multiset<int> s[N]; int m;
class segtree{ private: int tr[N<<2];
inline void pushup(int x){ tr[x] = min(tr[x<<1],tr[x<<1|1]); } public: segtree(){memset(tr,0x3f,sizeof(tr));}
void update(int u,int l,int r,int x,int c){ if(l==r){ tr[u] = c; return; } int mid = (l+r)>>1; if(x<=mid) update(u<<1,l,mid,x,c); else update(u<<1|1,mid+1,r,x,c); pushup(u); }
int query(int u,int l,int r,int L,int R){ if(l>=L&&r<=R) return tr[u]; int mid = (l+r)>>1,ans = 1e9; if(L<=mid) ans = min(ans,query(u<<1,l,mid,L,R)); if(R>mid) ans = min(ans,query(u<<1|1,mid+1,r,L,R)); return ans; } }tr;
void dfs1(int u){ siz[u] = 1; for(auto v:g[u]){ if(v==fa[u]) continue; fa[v] = u; dep[v] = dep[u]+1; dfs1(v); siz[u] += siz[v]; if(siz[v]>siz[son[u]]) son[u] = v; } }
void dfs2(int u,int tp){ dfn[u] = ++idx; top[u] = tp; if(son[u]) dfs2(son[u],tp); for(auto v:g[u]){ if(v==fa[u]||v==son[u]) continue; dfs2(v,v); } }
inline void add(int x,int c,bool flag=true){ if(flag&&fa[x]) s[fa[x]].erase(s[fa[x]].find(w[x])); w[x] = c; if(!fa[x]) return; s[fa[x]].insert(c); tr.update(1,1,m,dfn[fa[x]],*s[fa[x]].begin()); }
inline int query(int x,int y){ int ans = 1e9; while(top[x]!=top[y]){ if(dep[top[x]]<dep[top[y]]) swap(x,y); ans = min(ans,tr.query(1,1,m,dfn[top[x]],dfn[x])); x = fa[top[x]]; } if(dep[x]<dep[y]) swap(x,y); ans = min(ans,tr.query(1,1,m,dfn[y],dfn[x])); if(y<=n) ans = min(ans,w[y]); else ans = min(ans,w[fa[y]]); return ans; } }
namespace Graph{ vector<int> g[N]; int dfn[N],low[N],idx; int stk[N],top; int nod;
void dfs(int u,int father){ dfn[u] = low[u] = ++idx; stk[++top] = u; for(auto v:g[u]){ if(!dfn[v]){ dfs(v,u); low[u] = min(low[u],low[v]); if(low[v]>=dfn[u]){ nod++; do{ Tree::g[stk[top]].push_back(nod); Tree::g[nod].push_back(stk[top--]); }while(stk[top+1]!=v); Tree::g[u].push_back(nod); Tree::g[nod].push_back(u); } } else if(v!=father) low[u] = min(low[u],dfn[v]); } }
inline void build(){ nod = n; dfs(1,0); Tree::m = nod; } }
int main(){ n = in(),m = in(); int q = in(); for(int k=1;k<=n;k++) w[k] = in(); for(int k=1;k<=m;k++){ int a = in(),b = in(); Graph::g[a].push_back(b); Graph::g[b].push_back(a); } Graph::build(); Tree::dfs1(1); Tree::dfs2(1,1); for(int k=1;k<=n;k++) Tree::add(k,w[k],false); while(q--){ char ops = getchar(); while(ops!='C'&&ops!='A') ops = getchar(); int x = in(),y = in(); if(ops=='C') Tree::add(x,y); else{ out(Tree::query(x,y)); putchar('\n'); } } return 0; }
|