Under construction

Still being built. Things may change

Tasks for Indonesian Contests

Time limit1sMemory limit512 MB

Summary
Given authors linked to contests and topics, each with at most two links, find the maximum number of tasks that can be written.
Level

Hard8 of 10

Topics
Graph, DFS, Greedy
Solved
No attempts yet

Problem

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

There are TT topics in programming contest tasks, numbered from 11 to TT. 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 wants to write tasks only about topics in FiF_i. Each task author cannot write more than one task about the same topic.

Each contest 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 of each task written for the contest must be in SjS_j. Each contest cannot have more than one task for the same topic.

Each task author likes at most two contests, and each contest is liked by at most two task authors. Each task author is familiar with at most two topics, and each topic is familiar to at most two task authors. Each contest has at most two topics in its syllabus, and each topic appears in at most two contest syllabuses.

Find the maximum total number of tasks that can be written across all contests.

Input

The first line contains three integers AA, CC, TT (1≤A,C,T≤500001 \le A, C, T \le 50000).

The next AA lines each begin with ∣Li∣|L_i| (0≤∣Li∣≤20 \le |L_i| \le 2), followed by ∣Li∣|L_i| distinct contest numbers Li[x]L_i[x] (1≤Li[x]≤C1 \le L_i[x] \le C). Each contest number appears at most twice across all LiL_i.

The next AA lines each begin with ∣Fi∣|F_i| (0≤∣Fi∣≤20 \le |F_i| \le 2), followed by ∣Fi∣|F_i| distinct topic numbers Fi[y]F_i[y] (1≤Fi[y]≤T1 \le F_i[y] \le T). Each topic number appears at most twice across all FiF_i.

The next CC lines each begin with ∣Sj∣|S_j| (0≤∣Sj∣≤20 \le |S_j| \le 2), followed by ∣Sj∣|S_j| distinct topic numbers Sj[z]S_j[z] (1≤Sj[z]≤T1 \le S_j[z] \le T). Each topic number appears at most twice across all SjS_j.

Output

Print one integer on a line: the maximum total number of tasks that can be written across all contests.

Examples1

  1. Example 1

    Input
    2 3 2
    2 1 2
    2 2 3
    1 1
    1 1
    1 1
    1 1
    1 2
    
    Expected output
    2