0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-14 06:58:48 +00:00
OI-codes/S2OJ/1905/data/std.cpp

113 lines
3.0 KiB (Stored with Git LFS)
C++

#include<bits/stdc++.h>
using namespace std;
namespace IO{
template<typename T>inline bool read(T &x){
x=0;
char ch=getchar();
bool flag=0,ret=0;
while(ch<'0'||ch>'9') flag=flag||(ch=='-'),ch=getchar();
while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar(),ret=1;
x=flag?-x:x;
return ret;
}
template<typename T,typename ...Args>inline bool read(T& a,Args& ...args){
return read(a)&&read(args...);
}
template<typename T>void prt(T x){
if(x>9) prt(x/10);
putchar(x%10+'0');
}
template<typename T>inline void put(T x){
if(x<0) putchar('-'),x=-x;
prt(x);
}
template<typename T>inline void put(char ch,T x){
if(x<0) putchar('-'),x=-x;
prt(x);
putchar(ch);
}
template<typename T,typename ...Args>inline void put(T a,Args ...args){
put(a);
put(args...);
}
template<typename T,typename ...Args>inline void put(const char ch,T a,Args ...args){
put(ch,a);
put(ch,args...);
}
inline void putstr(string s){
for(int i=0,sz=s.length();i<sz;i++) putchar(s[i]);
}
}
using namespace IO;
#define N 200005
#define lc(x) (x<<1)
#define rc(x) (x<<1|1)
int n,m,k,tp,fa[N],dep[N],siz[N];
struct edge{
int u,v;
}e[N<<1];
struct operation{
int x,y,siz;
bool val;
}op[N<<3];
bool ans[N];
vector<int> edge[N<<1],p[N<<2];
inline void update(int x,int l,int r,int ul,int ur,int w){
if(ul>ur) return;
if(ul<=l&&ur>=r) return p[x].emplace_back(w),void();
int mid=l+r>>1;
if(ul<=mid) update(lc(x),l,mid,ul,ur,w);
if(ur>mid) update(rc(x),mid+1,r,ul,ur,w);
}
inline int getf(int x){
while(x!=fa[x]) x=fa[x];
return x;
}
inline void merge(int x,int y){
// x=getf(x),y=getf(y);
if(dep[x]>dep[y]) swap(x,y);
fa[x]=y;
op[++tp]=(operation){x,y,siz[x],dep[x]==dep[y]};
siz[y]+=siz[x];
if(dep[x]==dep[y]) dep[y]++;
}
inline void pop(){
dep[op[tp].y]-=op[tp].val;
siz[op[tp].y]-=op[tp].siz;
fa[op[tp].x]=op[tp].x;
tp--;
}
void solve(int x,int l,int r,int flag){
int lst=tp;
for(auto now:p[x]){
int a=getf(e[now].u),b=getf(e[now].v);
if(a==b) continue;
merge(a,b);
if(siz[a]==n||siz[b]==n) flag=1;
}
if(l==r) ans[l]=flag;
else{
int mid=l+r>>1;
solve(lc(x),l,mid,flag),solve(rc(x),mid+1,r,flag);
}
while(tp>lst) pop();
}
int main(){
read(n,m);
for(int i=1;i<=m;i++) read(e[i].u,e[i].v),edge[i].emplace_back(0);
read(k);
for(int i=1,x,y;i<=k;i++){
read(x);
while(x--) read(y),edge[y].emplace_back(i);
}
for(int i=1;i<=m;i++) edge[i].emplace_back(k+1);
for(int i=1;i<=m;i++)
for(int j=1;j<edge[i].size();j++)
if(edge[i][j-1]+1<=edge[i][j]-1)
update(1,1,k,edge[i][j-1]+1,edge[i][j]-1,i);
for(int i=1;i<=n;i++) siz[i]=dep[i]=1,fa[i]=i;
solve(1,1,k,0);
for(int i=1;i<=k;i++) putstr(ans[i]?"Connected\n":"Disconnected\n");
return 0;
}