2 条题解

  • 0
    @ 2024-12-28 14:21:40

    十分简单的一道题,令我脑部旋转

    #include <bits/stdc++.h>
    using namespace std;
    const int N = 105;
    int n, m, t, ans, a[N], vis[N], ind[N];
    vector <int> p[N];
    void pus(int x) {
    	vis[x] = 1;
    	for (int i = 0; i < p[x].size(); ++i) {
    		int to = p[x][i];
    		if (vis[to]) continue;
    		pus(to);
    	}
    }
    int main() {
    	scanf("%d", &n);
    	for (int i = 1; i <= n; ++i) {
    		scanf("%d", &t);
    		for (int j = 1, v; j <= t; ++j)
    			scanf("%d", &v), p[v].push_back(i);
    	}
    	scanf("%d", &m);
    	for (int i = 1; i <= m; ++i) {
    		memset(vis, 0, sizeof(vis));
    		for (int j = 1; j <= n; ++j) scanf("%d", &a[j]);
    		for (int j = 1; j <= n; ++j) 
    			if (!a[j])
    				pus(j);
    		int ans = 0;
    		for (int j = 1; j <= n; ++j)
    			if (!vis[j])
    				++ans;
    		printf("%d\n", ans);
    	}
    	return 0;
    }
    

    信息

    ID
    74
    时间
    3000ms
    内存
    512MiB
    难度
    2
    标签
    递交数
    263
    已通过
    163
    上传者