#ifndef LOCAL #pragma GCC optimize("O3") #endif #include using namespace std; #define sim template < class c #define ris return * this #define mor > muu & operator << ( #define R22(r) sim > typename \ enable_if<1 r sizeof dud(0), muu&>::type operator<<( c g) { sim > struct rge { c b, e; }; sim > rge range(c h, c n) { return {h, n}; } sim > auto dud(c * r) -> decltype(cerr << *r); sim > char dud(...); struct muu { #ifdef LOCAL stringstream a; ~muu() { cerr << a.str() << endl; } R22(<) a << boolalpha << g; ris; } R22(==) ris << range(begin(g), end(g)); } sim, class b mor pair < b, c> r) { ris << "(" << r.first << ", " << r.second << ")"; } sim mor rge u) { a << "["; for (c i = u.b; i != u.e; ++i) *this << ", " + 2 * (i == u.b) << *i; ris << "]"; } #else sim mor const c&) { ris; } #endif muu & operator()() { ris; } }; #define imie(r...) "[" #r ": " << (r) << "] " #define debug (muu() << __FUNCTION__ << "#" << __LINE__ << ": ") const int N = 100 * 1000 + 5; vector T[N], G[N], U[N]; set zap[N]; class FU { public: map global_to_local; vector fu; FU(vector x) { int n = x.size(); for (int i = 0; i < n; i ++) global_to_local[x[i]] = i; fu.resize(n); for (int i =0; i < n; i ++) fu[i] = i; } int fuf(int x) { if (fu[x] == x) return x; fu[x] = fuf(fu[x]); return fu[x]; } void fuu(int x, int y) { x = global_to_local[x]; y = global_to_local[y]; fu[fuf(x)] = fuf(y); } int skladowe() { int ans = 0; int n = fu.size(); for (int i = 0; i < n; i ++) { if (fu[i] == i) ans ++; } return ans; } }; vector fus; void process(int x, int y) { if (zap[y].size() < zap[x].size()) swap(x, y); for (int q : zap[x]) { if (zap[y].count(q) != 0) fus[q].fuu(x, y); } } vector last; vector vis; void dfs(int x, int id) { if (vis[x] == id) return; vis[x] = id; for (int y : U[x]) { if (vis[y] < id) dfs(y, id); } } void solve() { int n, e, p; cin >> n >> e >> p; for (int i = 0; i < e; i ++) { int a, b; cin >> a >> b; T[a].push_back(b); T[b].push_back(a); } vector taken(n+1, 0); vector dd(n+1); set> deg; for (int i= 1; i <= n; i ++) { deg.insert({T[i].size(), i}); dd[i] = T[i].size(); } while (!deg.empty()) { int x = deg.begin() -> second; taken[x] = 1; deg.erase(deg.begin()); for (int y : T[x]) { if (taken[y] == 0) { G[x].push_back(y); deg.erase({dd[y], y}); dd[y] --; deg.insert({dd[y], y}); } } } last.resize(n+1); vis.resize(n+1); for (int i =1; i <= p; i ++) { int k; cin >> k; vector x(k); for (int j= 0; j < k; j ++) { cin >> x[j]; last[x[j]] = i; } for (int a : x) { U[a].clear(); } for (int a : x) { for (int y : G[a]) { if (last[y] == i) { U[a].push_back(y); U[y].push_back(a); } } } int ans = 0; for (int a : x) { if (vis[a] < i) { ans ++; dfs(a, i); } } cout << ans << "\n"; } } int main() { ios_base::sync_with_stdio(0); solve(); }