PivotOJ

Writing Tasks

시간 제한: 1000ms메모리 제한: 512MB출처: ICPC Asia Jakarta Regional 2020BOJ 20693

문제

In 2020, there are CC programming contests held in Indonesia, numbered from 11 to CC. Each contest has zero or more tasks written for the contest. There are AA task authors who can write tasks for these contests, numbered from 11 to AA. The iith task author only likes the set of contests Li{1,2,,C}L_i \subseteq \{1, 2, \dots , C\}, and only wants to write tasks for contests in LiL_i. Each task author cannot write more than one task for the same contest.

There are also TT topics in programming contest tasks, numbered from 11 to TT. For example, topic 1 might be about graph tasks, topic 2 might be about string tasks, and so on. Each task has exactly one topic. The iith task author is familiar with the set of topics Fi{1,2,,T}F_i \subseteq \{1, 2, \dots , T\}, and only wants to write tasks about topics in FiF_i. Each task author cannot write more than one task about the same topic.

Additionally, each contest also has a syllabus. The jjth contest syllabus contains the set of topics Sj{1,2,,T}S_j \subseteq \{1, 2, \dots , T\}, and the topic for the tasks written for the contest must be in SjS_j. Each contest cannot have more than one task for the same topic.

You are a programming contest enthusiast in Indonesia. Surprisingly, you observed the following:

  • Each task author likes at most two contests. Similarly, each contest is liked by at most two task authors.
  • Each task author is familiar with at most two topics. Similarly, each topic is familiarized by at most two task authors.
  • Each contest has at most two topics in its syllabus. Similarly, each topic is present in at most two contest syllabuses.

You want to find the maximum total number of tasks that can be written across all contests.

입력

Input begins with a line containing three integers: ACTA C T (1A,C,T500001 \le A, C, T \le 50 000) representing the number of task authors, contests, and topics, respectively.

The next AA lines each begins with an integer: Li|L_i| (0Li20 \le |L_i| \le 2) representing the number of contests that the iith task author likes, followed by Li|L_i| integers: Li[x]L_i[x] (1Li[x]C1 \le L_i[x] \le C) representing the liked contests. It is guaranteed that the values in LiL_i are distinct. It is also guaranteed that for all 1jC1 \le j \le C, the value jj only appears at most twice in i=1ALi\bigcup_{i=1}^{A}{L_i}.

The next A lines each begins with an integer: Fi|F_i| (0Fi20 \le |F_i| \le 2) representing the number of topics that the iith task author is familiar with, followed by Fi|F_i| integers: Fi[y]F_i[y] (1Fi[y]T1 \le F_i[y] \le T) representing the familiarized topics. It is guaranteed that the values in FiF_i are distinct. It is also guaranteed that for all 1kT1 \le k \le T, the value kk only appears at most twice in i=1AFi\bigcup_{i=1}^{A}{F_i}.

The next CC lines each begins with an integer: Sj|S_j| (0Sj20 \le |S_j| \le 2) representing the number of topics in the jjth contest syllabus, followed by Sj|S_j| integers: Sj[z]S_j[z] (1Sj[z]T1 \le S_j[z] \le T) representing the topics in the syllabus. It is guaranteed that the values in SjS_j are distinct. It is also guaranteed that for all 1kT1 \le k \le T, the value kk only appears at most twice in j=1CSj\bigcup_{j=1}^{C}{S_j}.

출력

Output in a line an integer representing the maximum total number of tasks that can be written across all contests.

예제

예제 1

입력
2 3 2
2 1 2
2 2 3
1 1
1 1
1 1
1 1
1 2
출력
2
코드를 제출하려면 로그인하세요.