2 条题解
-
0
十分简单的一道题,令我脑部旋转
#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; }
-
0
Answer is here!
#include<bits/stdc++.h> using namespace std; int s[114][514],d[114]; bool o[114]; int main() { int n; cin>>n; for(int i=1;i<=n;i++) { cin>>d[i]; for(int j=1;j<=d[i];j++)cin>>s[i][j]; } int m; cin>>m; while(m--) { int ans=0; for(int i=1;i<=n;i++) { cin>>o[i]; } for(int i=1;i<=n;i++) { for(int j=1;j<=d[i];j++) { if(!o[s[i][j]])o[i]=0; } } for(int i=1;i<=n;i++)if(o[i])ans++; cout<<ans<<endl; } }
Thank you very much!
- 1
信息
- ID
- 74
- 时间
- 3000ms
- 内存
- 512MiB
- 难度
- 2
- 标签
- 递交数
- 263
- 已通过
- 163
- 上传者