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
#include <cstdio>
#include <cstdlib>
#include <cstring>

static unsigned gcd(unsigned a, unsigned b)
{
	unsigned c;

	while (b) {
		c = a % b;
		a = b;
		b = c;
	}

	return a;
}

static unsigned multiplier[101];
static bool reachable[101];

int main(void)
{
	unsigned n, i;
	unsigned long long r = 1;

	scanf("%u", &n);

	reachable[1] = true;

	for (i = 1; i <= n; i++) {
		unsigned m, j;

		scanf("%u", &m);
		multiplier[i] = m;
		for (j = 0; j < m; j++) {
			unsigned target;

			scanf("%u", &target);
			if (reachable[i]) {
				reachable[target] = true;
			}
		}
	}

	for (i = 1; i <= n; i++) {
		if (reachable[i] && multiplier[i]) {
			unsigned long long m = multiplier[i];
			unsigned long long x = r * m;
			unsigned long long y = gcd(r, m);

			r = x / y; 
		}
	}

	printf("%llu\n", r);

	return 0;
}