【省选模拟】—Cactus(圆方树+dfs序)
割点也建一个方点要好做一点
建出圆方树后就差不多了吧。。。
处理一下如果是方点会对上面那个圆点有贡献
开个桶记一下就完了
#include<bits/stdc++.h>
using namespace std;
const int RLEN=1<<18|1;
inline char gc(){
static char ibuf[RLEN],*ib,*ob;
(ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
return (ib==ob)?EOF:*ib++;
}
inline int read(){
char ch=gc();
int res=0,f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
const int N=1e6+5;
const int mod=998244353;
inline int add(int a,int b){
return a+b>=mod?a+b-mod:a+b;
}
inline int dec(int a,int b){
return a<b?a-b+mod:a-b;
}
inline void ad(int &a,int b){
a=a+b,a<mod?0:a-=mod;
}
struct Graph{
int adj[N],nxt[N<<1],to[N<<1],cnt;
inline void addedge(int u,int v){
nxt[++cnt]=adj[u],adj[u]=cnt,to[cnt]=v;
nxt[++cnt]=adj[v],adj[v]=cnt,to[cnt]=u;
}
}T,G;
int low[N],dfn[N],tot,bel,ori[N];
stack<int> stk;
void tarjan(int u){
low[u]=dfn[u]=++tot;stk.push(u);
for(int e=G.adj[u];e;e=G.nxt[e]){
int v=G.to[e];
if(!dfn[v]){
tarjan(v),low[u]=min(low[u],low[v]);
if(low[v]>=dfn[u]){
int tmp;bel++;
T.addedge(bel,u);
do{
tmp=stk.top(),stk.pop();
T.addedge(bel,tmp);
}while(tmp!=v);
}
}
else low[u]=min(low[u],dfn[v]);
}
}
int n,m,q;
namespace SLPF{
int pos[N],out[N],fa[N],top[N],dep[N],siz[N],son[N],tot,val[N];
void dfs1(int u){
siz[u]=1;
for(int e=T.adj[u];e;e=T.nxt[e]){
int v=T.to[e];
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){
top[u]=tp;if(u>n)pos[u]=++tot;else pos[u]=pos[fa[u]];
if(son[u])dfs2(son[u],tp);
for(int e=T.adj[u];e;e=T.nxt[e]){
int v=T.to[e];
if(v==fa[u]||v==son[u])continue;
dfs2(v,v);
}
out[u]=tot;
}
inline int Lca(int u,int v){
while(top[u]!=top[v]){
if(dep[top[u]]<dep[top[v]])swap(u,v);
u=fa[top[u]];
}
return dep[u]>dep[v]?v:u;
}
int tr[N];
#define lowbit(x) (x&(-x))
inline void update(int p,int k){
for(;p&&p<=tot;p+=lowbit(p))ad(tr[p],k);
}
inline int qry(int p,int res=0){
for(;p;p-=lowbit(p))ad(res,tr[p]);return res;
}
inline int query(int l,int r){
return dec(qry(r),qry(l-1));
}
#undef lowbit
inline void update(int u,int v,int k){
int lca=Lca(u,v);
update(pos[u],k),update(pos[v],k);
update(pos[lca],mod-k);if(fa[lca])update(pos[fa[lca]],mod-k);
if(lca<=n)ad(val[lca],k);
else ad(val[fa[lca]],k);
}
inline int query(int u){
return add(val[u],query(pos[fa[u]],out[fa[u]]));
}
}
signed main(){
bel=n=read(),m=read(),q=read();
for(int i=1;i<=m;i++){
int u=read(),v=read();
G.addedge(u,v);
}
tarjan(1);
SLPF::dfs1(bel),SLPF::dfs2(bel,bel);
while(q--){
int op=read();
if(op==0){
int u=read(),v=read(),k=read();
SLPF::update(u,v,k);
}
else {
int u=read();
cout<<SLPF::query(u)<<'\n';
}
}
}