标签:nod space tchar tin continue ons int acl code
#include<bits/stdc++.h> #define il inline #define reg register int #define numb (ch^‘0‘) using namespace std; typedef long long ll; il void rd(int &x){ char ch;bool fl=false; while(!isdigit(ch=getchar()))(ch==‘-‘)&&(fl=true); for(x=numb;isdigit(ch=getchar());x=x*10+numb); (fl==true)&&(x=-x); } namespace Miracle{ const int N=100000+5; int n,m,q; struct node{ int nxt,to; }e[2*N]; int hd[N],cnt; void add(int x,int y){ e[++cnt].nxt=hd[x]; e[cnt].to=y; hd[x]=cnt; } int fa[N][19]; int dep[N]; int a[2*N],tot; int in[N],out[N]; ll w[N],v[N]; int c[N]; void dfs(int x,int d){ dep[x]=d; a[++tot]=x;in[x]=tot; for(reg i=hd[x];i;i=e[i].nxt){ int y=e[i].to; if(y==fa[x][0]) continue; fa[y][0]=x; dfs(y,d+1); } a[++tot]=x;out[x]=tot; } int lca(int x,int y){ if(dep[x]<dep[y]) swap(x,y); for(reg j=17;j>=0;--j){ if(dep[fa[x][j]]>=dep[y]) x=fa[x][j]; } if(x==y) return x; for(reg j=17;j>=0;--j){ if(fa[x][j]!=fa[y][j]) x=fa[x][j],y=fa[y][j]; } return fa[x][0]; } int be[2*N]; struct que{ int id,l,r,t; int lca; bool friend operator <(que a,que b){ 2333 } }; int buc[N]; ll now; struct event{ int x,id; }h[N]; int num1,num2; ll ans[N]; void chan(int x,int c){ } void wrk(){ } int main(){ rd(n);rd(m);rd(q); int blo=sqrt(q); for(reg i=1;i<=m;++i) rd(v[i]); for(reg i=1;i<=n;++i) rd(w[i]); int x,y; for(reg i=1;i<n;++i){ rd(x);rd(y);add(x,y);add(y,x); } for(reg i=1;i<=n;++i){ rd(c[i]); } dfs(1,1); for(reg j=1;j<=17;++j) for(reg i=1;i<=n;++i){ fa[i][j]=fa[fa[i][j-1]][j-1]; } for(reg i=1;i<=tot;++i){ be[i]=(i-1)/blo+1; } num1=0; int op,x,y,c; for(reg i=1;i<=q;++i){ rd(op); if(op==0){ ++num1; rd(x);rd(y); h[num1].x=x;h[num1].id=y; }else{ ++num2; rd(x);rd(y); q[num2].id=num2; q[num2].t=num1; int anc=lca(x,y); if(anc==x||anc==y){ if(in[x]>in[y]) swap(x,y); q[num2].l=in[x],q[num2].r=in[y]; q[num2].lca=0; }else{ q[num2].lca=anc; if(out[x]>in[y]) swap(x,y); q[num2].l=out[x],q[num2].r=in[y]; } } } sort(q+1,q+num2+1); wrk(); for(reg i=1;i<=num2;++i){ printf("%lld\n",ans[i]); } return 0; } } signed main(){ Miracle::main(); return 0; } /* Author: *Miracle* Date: 2019/3/24 12:28:10 */
标签:nod space tchar tin continue ons int acl code
原文地址:https://www.cnblogs.com/Miracevin/p/10587715.html