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
| #include<bits/stdc++.h> #define LL long long #define mod 19260817 using namespace std; inline int read(){ int res=0,f=1;char ch=getchar(); while(ch<'0'ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9') res=res*10+ch-'0',ch=getchar(); return res*f; } inline void write(int x){ if(x<0) putchar('-'),x=-x; if(x<10) putchar(x+'0'); else write(x/10),putchar(x%10+'0'); } int n,m,q,fa[400010],vis[400010],A,C,ans[400010],Z[400010]; LL fac[400010*4]; inline LL fpow(LL a,LL b){ LL s=1; while(b){ if(b&1) s*=a,s%=mod; a*=a;a%=mod; b>>=1; } return s; } struct Edge{ int x,y; }E[400010]; struct Question{ int op,x,y,z; }Q[400010]; map<int,int> v[400010]; vector<int> g[400010]; inline int getfa(int x){ int a=x,y; while(x!=fa[x]) x=fa[x]; while(a!=x) y=a,a=fa[a],fa[y]=x; return x; } inline void merge(int x,int y){ x=getfa(x);y=getfa(y); if(x==y) return ; if(v[x].size()<v[y].size()) swap(x,y); fa[y]=x;Z[x]+=Z[y]; for(int i:g[y]){ if(v[x][i]==0&&v[y][i]!=0) g[x].push_back(i); v[x][i]+=v[y][i]; } Z[y]=0; v[y].clear(); g[y].clear(); } int main(){ n=read(),m=read(),q=read(); fac[0]=1; for(int i=1;i<=4*400000;i++){ fac[i]=(LL)fac[i-1]*i%mod; } for(int x,y,i=1;i<=n;i++){ x=read();y=read(); fa[i]=i; v[i].clear(); g[i].clear(); g[i].push_back(y); v[i][y]+=x; Z[i]=x; } for(int i=1;i<=m;i++){ E[i].x=read(),E[i].y=read(); } for(int i=1;i<=q;i++){ Q[i].op=read(); if(Q[i].op==1){ Q[i].x=read(),Q[i].y=read(),Q[i].z=read(); if(v[Q[i].x][Q[i].z]==0) g[Q[i].x].push_back(Q[i].z); v[Q[i].x][Q[i].z]+=Q[i].y; Z[Q[i].x]+=Q[i].y; }else if(Q[i].op==2){ Q[i].x=read(); vis[Q[i].x]=1; }else if(Q[i].op==3){ Q[i].x=read(),Q[i].y=read(),Q[i].z=read(); } } for(int i=1;i<=m;i++){ if(vis[i]==0) merge(E[i].x,E[i].y); } for(int i=q;i>=1;i--){ if(Q[i].op==1){ Q[i].x=getfa(Q[i].x); v[Q[i].x][Q[i].z]-=Q[i].y; Z[Q[i].x]-=Q[i].y; if(v[Q[i].x][Q[i].z]==0) g[Q[i].x].erase(find(g[Q[i].x].begin(),g[Q[i].x].end(),Q[i].z)); }else if(Q[i].op==2){ merge(E[Q[i].x].x,E[Q[i].x].y); }else if(Q[i].op==3){ Q[i].x=getfa(Q[i].x); A=C=0;A=Z[Q[i].x];C=v[Q[i].x][Q[i].z]; LL tmp1=fac[C]*fac[A-Q[i].y]%mod; LL tmp2=fac[A]*fac[C-Q[i].y]%mod; tmp2=fpow(tmp2,mod-2); LL res=tmp1*tmp2; res+=mod;res%=mod; ans[i]=res; } } for(int i=1;i<=q;i++) if(Q[i].op==3) write(ans[i]),putchar('\n'); }
|