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
|
#include<iostream> #include<cstdio> #include<vector> #include<ctime> 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; const int M=200000+100; int n,m,q,p,ans[M]; struct UnF { int size[N],fa[N],mstack[M],top; void Init() { for(int i=1;i<=n;i++) size[i]=1; } int FindFather(int x) { if(fa[x]==0) return x; return FindFather(fa[x]); } void Link(int x,int y) { mstack[++top]=0; int fa_x=FindFather(x),fa_y=FindFather(y); if(size[fa_x]>size[fa_y]) swap(x,y),swap(fa_x,fa_y); if(fa_x==fa_y) return; mstack[top]=fa_x; fa[fa_x]=fa_y,size[fa_y]+=size[fa_x]; } int Query() { if(size[FindFather(1)]==n) return true; return false; } void Undo() { if(mstack[top]==0) { top--; return; } size[fa[mstack[top]]]-=size[mstack[top]]; fa[mstack[top]]=0; top--; } }unf; struct OP { int s,t,id; }op2[M*20],e[M]; struct SegmentTree { #define mid ((now_l+now_r)>>1) #define lson (now<<1) #define rson (now<<11) vector <int> w[M<<2]; void Insert(int l,int r,int 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) Insert(l,r,x,lson,now_l,mid); if(r>mid) Insert(l,r,x,rson,mid+1,now_r); } void dfs(int now,int now_l,int now_r) { if(now_l>now_r) return; for(int i=0;i<int(w[now].size());i++) unf.Link(e[w[now][i]].s,e[w[now][i]].t); if(now_l==now_r) ans[now_l]=unf.Query(); else { dfs(lson,now_l,mid); dfs(rson,mid+1,now_r); } for(int i=0;i<int(w[now].size());i++) unf.Undo(); } #undef mid #undef lson #undef rson }sgt; int last[M],K; int main() { n=read(),m=read(); for(int i=1;i<=m;i++) e[i].s=read(),e[i].t=read(),last[i]=1; K=read(); for(int i=1;i<=K;i++) { int c=read(); for(int j=1;j<=c;j++) { int x=read(); op2[++p].s=last[x],op2[p].t=i-1,op2[p].id=x; last[x]=i+1; } } for(int i=1;i<=m;i++) if(last[i]!=K+1) op2[++p].s=last[i],op2[p].t=K,op2[p].id=i;
for(int i=1;i<=p;i++) if(op2[i].s<=op2[i].t) { sgt.Insert(op2[i].s,op2[i].t,op2[i].id,1,1,K); }
unf.Init(); sgt.dfs(1,1,K);
for(int i=1;i<=K;i++) if(ans[i]==0) printf("Disconnected\n"); else printf("Connected\n"); return 0; }
|