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 140 141 142 143 144 145
|
#include<iostream> #include<cstdio> #include<vector> 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=100000+100; struct edge { int s,t; edge (int x,int y) { s=x,t=y; } }; struct UnF { int fa[N],size[N],dis[N],depth[N],top,mstack[N*20]; void Init(int n) { for(int i=1;i<=n;i++) depth[i]=size[i]=1; } int GetFa(int x,int &w) { if(fa[x]==0) { w++; return x; } int t=GetFa(fa[x],w+=dis[x]+1); depth[x]=depth[fa[x]]+1; return t; } int LCA(int x,int y,int &w) { w=1; if(depth[x]<depth[y]) swap(x,y); while(depth[x]>depth[y]) w+=dis[x]+1,x=fa[x]; if(x==y) return x; w++; while(fa[x]!=fa[y]) { w+=dis[x]+1,w+=dis[y]+1; x=fa[x],y=fa[y]; } w+=dis[x]+dis[y]+1; return fa[x]; } int Link(int x,int y) { int d1=0,d2=0,fa1=GetFa(x,d1),fa2=GetFa(y,d2); if(size[fa1]>size[fa2]) swap(x,y),swap(fa1,fa2),swap(d1,d2); mstack[++top]=0; if(fa1==fa2) { int t_d=0; LCA(x,y,t_d); if(t_d%2==1) return 1; return 0; } mstack[top]=fa1; dis[fa1]=d1+d2-2,fa[fa1]=fa2,size[fa2]+=size[fa1]; return 0; } void Undo() { if(mstack[top]!=0) size[fa[mstack[top]]]-=size[mstack[top]],fa[mstack[top]]=0, dis[mstack[top]]=0,depth[mstack[top]]=1; top--; } }unf; int ans[N],top,OK; struct SegmentTree { #define mid ((now_l+now_r)>>1) #define lson (now<<1) #define rson (now<<11) vector <edge> w[N<<2]; void Add(int l,int r,edge x,int now,int now_l,int now_r) { if(now_l>=l and now_r<=r) { w[now].push_back(x); return; } if(l<=mid) Add(l,r,x,lson,now_l,mid); if(r>mid) Add(l,r,x,rson,mid+1,now_r); } void dfs(int now,int now_l,int now_r) { int cnt=0; for(int i=0;i<int(w[now].size());i++) cnt+=unf.Link(w[now][i].s,w[now][i].t); OK+=cnt; if(now_l==now_r) ans[now_l]=OK; else { dfs(lson,now_l,mid); dfs(rson,mid+1,now_r); } OK-=cnt; for(int i=0;i<int(w[now].size());i++) unf.Undo(); } #undef mid #undef lson #undef rson }sgt; int n,m,q; int main() { n=read(),m=read(),q=read(); unf.Init(n); for(int i=1;i<=m;i++) { int u=read(),v=read(),s=read(),t=read(); sgt.Add(s+1,t,edge(u,v),1,1,q); } sgt.dfs(1,1,q); for(int i=1;i<=q;i++) if(ans[i]==0) printf("Yes\n"); else printf("No\n"); return 0; }
|