mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-14 06:58:48 +00:00
37 lines
1.1 KiB (Stored with Git LFS)
C++
37 lines
1.1 KiB (Stored with Git LFS)
C++
#include <bits/stdc++.h>
|
|
#include "testlib.h"
|
|
using namespace std;
|
|
const int N=1e5,M=2e5,K=4;
|
|
int fa[N+10];
|
|
int find(int x){
|
|
if (fa[x]!=x) fa[x]=find(fa[x]);
|
|
return fa[x];
|
|
}
|
|
void merge(int x, int y){
|
|
fa[find(x)]=find(y);return;
|
|
}
|
|
int main(int argc, char** argv){
|
|
registerValidation();
|
|
int n=inf.readInt(1,N);inf.readSpace();
|
|
int m=inf.readInt(1,M);inf.readChar('\n');
|
|
map<pair<int,int>,int> mp;
|
|
for (int i=1;i<=m;i++){
|
|
int u=inf.readInt(1,n);inf.readSpace();
|
|
int v=inf.readInt(1,n);inf.readChar('\n');
|
|
ensuref(u!=v,"Graph can't contain loops");
|
|
ensuref(!mp[{min(u,v),max(u,v)}],"Graph can't contain multiple edges between a pair of vertices");
|
|
mp[{min(u,v),max(u,v)}]=1;merge(u,v);
|
|
}for (int i=1;i<=n;i++){
|
|
ensuref(find(i)==find(1),"Graph must be connected");
|
|
}int q=inf.readInt(1,N);inf.readChar('\n');
|
|
for (int i=1;i<=q;i++){
|
|
int c=inf.readInt(1,m);map<int,int> mp;
|
|
ensuref(c>=1&&c<=4,"Variable c must be >= 1 and <= 4");
|
|
for (int j=1;j<=c;j++){
|
|
inf.readSpace();int x=inf.readInt(1,m);
|
|
ensuref(!mp[x],"Set can't contain same elements");
|
|
mp[x]=1;
|
|
}inf.readChar('\n');
|
|
}inf.readEof();return 0;
|
|
}
|