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
| #include<iostream> #include<cstdio> #include<cstring> #include<cctype> #include<algorithm> #include<cmath> #include<set> using namespace std; inline int read(){ int w=0,x=0;char c=getchar(); while(!isdigit(c))w|=c=='-',c=getchar(); while(isdigit(c))x=(x<<3)+(x<<1)+(c^48),c=getchar(); return w?-x:x; } namespace star { const int maxn=2e5+10,INF=0x3f3f3f3f; int n,m,Q,a[maxn],cnt; struct gragh{ int ecnt,head[maxn],to[maxn<<1],nxt[maxn<<1]; inline void addedge(int a,int b){ to[++ecnt]=b,nxt[ecnt]=head[a],head[a]=ecnt; to[++ecnt]=a,nxt[ecnt]=head[b],head[b]=ecnt; } }G1,G2; int st[maxn],dfn[maxn],tot,id[maxn]; struct SegmentTree{ #define ls (ro<<1) #define rs (ro<<1|1) #define mid ((l+r)>>1) int mn[maxn<<2]; inline void pushup(const int &ro){ mn[ro]=min(mn[ls],mn[rs]); } void build(const int& ro=1,const int &l=1,const int &r=cnt){ if(l==r) return mn[ro]=a[id[l]],void(); build(ls,l,mid);build(rs,mid+1,r); pushup(ro); } void update(const int &x,const int &ro=1,const int &l=1,const int &r=cnt){ if(l==r) return mn[ro]=a[id[l]],void(); if(x<=mid) update(x,ls,l,mid); else update(x,rs,mid+1,r); pushup(ro); } int query(const int &x,const int &y,const int &ro=1,const int &l=1,const int &r=cnt){ if(x==l and y==r) return mn[ro]; if(y<=mid) return query(x,y,ls,l,mid); else if(x>mid) return query(x,y,rs,mid+1,r); else return min(query(x,mid,ls,l,mid),query(mid+1,y,rs,mid+1,r)); } #undef ls #undef rs #undef mid }T; void tarjan(int x){ dfn[x]=id[x]=++tot; st[++st[0]]=x; for(int i=G1.head[x];i;i=G1.nxt[i]){ int u=G1.to[i]; if(!dfn[u]){ tarjan(u); id[x]=min(id[x],id[u]); if(id[u]>=dfn[x]){ cnt++; int now=-1; G2.addedge(x,cnt); while(now^u) now=st[st[0]--],G2.addedge(now,cnt); } }else id[x]=min(id[x],dfn[u]); } } int dep[maxn],siz[maxn],fa[maxn],son[maxn],top[maxn]; multiset<int> q[maxn]; void dfs1(int x,int f){ fa[x]=f,dep[x]=dep[f]+1,siz[x]=1; for(int i=G2.head[x];i;i=G2.nxt[i]){ int u=G2.to[i]; if(u==f)continue; dfs1(u,x); if(x>n) q[x-n].insert(a[u]); siz[x]+=siz[u]; if(siz[u]>siz[son[x]])son[x]=u; } if(x>n) a[x]=*q[x-n].begin(); } void dfs2(int x,int topf){ top[x]=topf,dfn[x]=++tot,id[tot]=x; if(!son[x])return; dfs2(son[x],topf); for(int i=G2.head[x];i;i=G2.nxt[i]){ int u=G2.to[i]; if(u==fa[x] or u==son[x])continue; dfs2(u,u); } } inline int LCA(int x,int y){ int ans=INF; while(top[x]!=top[y]){ if(dep[top[x]]<dep[top[y]]) swap(x,y); ans=min(ans,T.query(dfn[top[x]],dfn[x])); x=fa[top[x]]; } if(dep[x]<dep[y])swap(x,y); ans=min(ans,T.query(dfn[y],dfn[x])); if(y>n) ans=min(ans,a[fa[y]]); return ans; } inline bool gc(){ char c=getchar(); while(!isalpha(c))c=getchar(); return c=='C'; } inline void work(){ n=cnt=read(),m=read(),Q=read(); for(int i=1;i<=n;i++) a[i]=read(); for(int i=1;i<=m;i++) G1.addedge(read(),read()); tarjan(1); tot=0; dfs1(1,0); dfs2(1,1); T.build(); while(Q--) if(gc()){ int x=read(),w=read(),u=fa[x]; if(u) q[u-n].erase(q[u-n].find(a[x])), q[u-n].insert(w), a[u]=*q[u-n].begin(), T.update(dfn[u]); a[x]=w; T.update(dfn[x]); }else printf("%d\n",LCA(read(),read())); } } signed main(){ star::work(); return 0; }
|