1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <cstdio>
#include <unordered_set>
#include <vector>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define VAR(v,w) __typeof(w) v=(w)
#define FORE(it,c) for(VAR(it,(c).begin());it!=(c).end();++it)
#define PB push_back
#define SIZE(c) ((int)(c).size())
#define INT(x) int x; scanf("%d", &x)

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;

VVI p;

int main() {
	INT(n);
	p.resize(n);
	REP(i,n) {
		INT(l);
		p.reserve(l);
		REP(j,l) {
			INT(x);
			p[i].PB(x - 1);
		}
	}
	REP(k,n) {
		LL r = 0;
		REP(to,k+1) {
			unordered_set<int> from;
			from.insert(to);
			unordered_set<int> notFrom;
			REP(i,k+1) if (i != to) notFrom.insert(i);
			bool change = 0;
			do {
				change = 0;
				int toAdd = -1;
				FORE(it,notFrom) {
					bool ok = 1;
					FORE(jt,p[*it]) if (from.find(*jt) == from.end()) {
						ok = 0;
						break;
					}
					if (ok) {
						toAdd = *it;
						change = 1;
						break;
					}
				}
				if (toAdd >= 0) {
					from.insert(toAdd);
					notFrom.erase(toAdd);
				}
			} while (change);
			r += SIZE(from) - 1;
		}
		if (k) printf(" ");
		printf("%lld", r);
	}
	printf("\n");
}