#P15597. [ICPC 2020 Jakarta R] Writing Tasks

[ICPC 2020 Jakarta R] Writing Tasks

题目描述

In 20202020, 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 ithi^\text{th} 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 11 might be about graph tasks, topic 22 might be about string tasks, and so on. Each task has exactly one topic. The ithi^\text{th} 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 cannot write more than one task about the same topic.

Additionally, each contest also has a syllabus. The jthj^\text{th} 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: A C TA\ C\ T (1A,C,T500001 \leq A, C, T \leq 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 \leq |L_i| \leq 2) representing the number of contests that the ithi^\text{th} task author likes, followed by Li|L_i| integers: Li[x]L_i[x] (1Li[x]C1 \leq L_i[x] \leq C) representing the liked contests. It is guaranteed that the values in LiL_i are distinct. It is also guaranteed that for all 1jC1 \leq j \leq C, the value jj only appears at most twice in i=1ALi\bigcup_{i=1}^A L_i.

The next AA lines each begins with an integer: Fi|F_i| (0Fi20 \leq |F_i| \leq 2) representing the number of topics that the ithi^\text{th} task author is familiar with, followed by Fi|F_i| integers: Fi[y]F_i[y] (1Fi[y]T1 \leq F_i[y] \leq T) representing the familiarized topics. It is guaranteed that the values in FiF_i are distinct. It is also guaranteed that for all 1kT1 \leq k \leq 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 \leq |S_j| \leq 2) representing the number of topics in the jthj^\text{th} contest syllabus, followed by Sj|S_j| integers: Sj[z]S_j[z] (1Sj[z]T1 \leq S_j[z] \leq 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 \leq k \leq 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.

2 3 2
2 1 2
2 2 3
1 1
1 1
1 1
1 1
1 2
2

提示

Explanation for the sample input/output #1

There are at most two tasks that can be written:

  1. The 1st1^\text{st} task author writes a task about the 1st1^\text{st} topic for the 1st1^\text{st} contest.
  2. The 2nd2^\text{nd} task author writes a task about the 1st1^\text{st} topic for the 2nd2^\text{nd} contest.

Note that the 1st1^\text{st} task author has written a task about the 1st1^\text{st} topic, thus they cannot write a task for the 2nd2^\text{nd} contest about the same topic.

This example can be illustrated by the following figure, with AiA_i represents the ithi^\text{th} task author, CjC_j represents the jthj^\text{th} contest, TkT_k represents the kthk^\text{th} topic, thick lines represent the first task, and the dashed lines represent the second task.

:::align{center} :::