#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 G[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); } } void solve() { int n, e, p; cin >> n >> e >> p; for (int i = 0; i < e; i ++) { int a, b; cin >> a >> b; G[a].push_back(b); G[b].push_back(a); } for (int i =0; i < p; i ++) { int k; cin >> k; vector x(k); for (int j= 0; j < k; j ++) { cin >> x[j]; zap[x[j]].insert(i); } fus.push_back(FU(x)); } for (int i = 1; i <= n; i ++) { for (int y : G[i]) { process(i, y); } } for (auto& x : fus) { cout << x.skladowe() << "\n"; } } int main() { ios_base::sync_with_stdio(0); solve(); }