待填坑
Code
//Luogu P1600 天天爱跑步//Apr,4th,2018//树上差分+LCA#include#include #include using namespace std;long long read(){ long long x=0,f=1; char c=getchar(); while(!isdigit(c)){ if(c=='-') f=-1;c=getchar();} while(isdigit(c)){x=x*10+c-'0';c=getchar();} return x*f;}const int N=300000+100;vector e[N];int n,m;int fa[N][21],depth[N],T[N];void dfs(int now){ for(int i=1;i<=20;i++) fa[now][i]=fa[fa[now][i-1]][i-1]; for(int i=0;i =0;i--) if(depth[fa[x][i]]>=depth[y]) x=fa[x][i]; if(x==y) return x; for(int i=20;i>=0;i--) if(fa[x][i]!=fa[y][i]) x=fa[x][i],y=fa[y][i]; return fa[x][0];}struct mark{ int count,num;};vector mk1[N],mk2[N];int ans[N],MK1[N*10],MK2[N*10];void dfs2(int now){ int rec1=MK1[T[now]+depth[now]],rec2=MK2[T[now]-depth[now]+2*N]; for(int i=0;i depth[now]) dfs2(e[now][i]); for(int i=0;i