#include using namespace std; #define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) #define REP(i, n) FOR(i, 0, n) #define TRACE(x) cerr << #x << " = " << x << endl #define _ << " _ " << #define pb push_back #define x first #define y second #define LT < #define GT > typedef long long ll; typedef long double lf; const int MAXN = 1e5 + 10; vector susjedi[MAXN]; vector graf[MAXN]; int n, m, q; vector pomocni_graf[MAXN]; vector aktivni; int bio[MAXN]; int trenutni[MAXN]; void obrisi_aktivni() { aktivni.clear(); } void obrisi_pomocni_graf() { REP(i, (int) aktivni.size()) pomocni_graf[aktivni[i]].clear(); obrisi_aktivni(); } int brojac; void pomocni_dfs(int cvor) { if(bio[cvor] == brojac) return; bio[cvor] = brojac; REP(i, (int) pomocni_graf[cvor].size()) pomocni_dfs(pomocni_graf[cvor][i]); } void obicni_dfs(int cvor) { if(trenutni[cvor] != brojac) return; if(bio[cvor] == brojac) return; bio[cvor] = brojac; REP(i, (int) graf[cvor].size()) obicni_dfs(graf[cvor][i]); } int main(void) { ios::sync_with_stdio(false); scanf("%d %d %d", &n, &m, &q); REP(i, m) { int a, b; scanf("%d %d", &a, &b); graf[a].push_back(b); graf[b].push_back(a); susjedi[a].push_back(b); susjedi[b].push_back(a); } FOR(i, 1, n + 1) sort(susjedi[i].begin(), susjedi[i].end()); REP(br, q) { brojac++; int k; scanf("%d", &k); vector v; REP(i, k) { int x; scanf("%d", &x); v.push_back(x); } if(k <= 100) { obrisi_pomocni_graf(); aktivni = v; REP(i, k) FOR(j, i + 1, k) { int a = v[i]; int b = v[j]; //cout << ": " << a << " " << b << endl; auto it = lower_bound(susjedi[a].begin(), susjedi[a].end(), b); if(it != susjedi[a].end() && *it == b) { pomocni_graf[a].push_back(b); pomocni_graf[b].push_back(a); } } int broj_komponenti = 0; REP(i, k) { if(bio[v[i]] != brojac) { pomocni_dfs(v[i]); broj_komponenti++; } } printf("%d\n", broj_komponenti); } else { int broj_komponenti = 0; REP(i, k) trenutni[v[i]] = 1; REP(i, k) { if(bio[v[i]] != brojac) { obicni_dfs(v[i]); broj_komponenti++; } } printf("%d\n", broj_komponenti); } } return 0; }