标签:dfs
4 4 1 1 1 2 1 3 1 4 2 4 3 1 2 3 4 1 2 3 4
15 2
#include <map> #include <set> #include <list> #include <queue> #include <stack> #include <vector> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; int jihe[2222]; bool vis[33333]; int ans, n; void dfs(int x, int v) { for (int i = 1; i <= n; ++i) { if (vis[v | jihe[i]] || i == x) { continue; } vis[v | jihe[i]] = 1; ans++; dfs(i, v | jihe[i]); } } int main() { int m, k, pos; while (~scanf("%d%d", &n, &m)) { memset (vis, 0, sizeof(vis)); memset (jihe, 0, sizeof(jihe)); ans = 0; for (int i = 1; i <= n; ++i) { scanf("%d", &k); for (int j = 0; j < k; ++j) { scanf("%d", &pos); jihe[i] |= (1 << pos); } if (vis[jihe[i]]) { continue; } vis[jihe[i]] = 1; ans++; } for (int i = 1; i <= n; ++i) { dfs(i, jihe[i]); } printf("%d\n", ans); } return 0; }
标签:dfs
原文地址:http://blog.csdn.net/guard_mine/article/details/41217069