Tasks for Indonesian Contests
Time limit1sMemory limit512 MB
Given authors linked to contests and topics, each with at most two links, find the maximum number of tasks that can be written.
Problem
In 2020, there are programming contests held in Indonesia, numbered from to . Each contest has zero or more tasks written for it. There are task authors who can write tasks for these contests, numbered from to . The th task author likes only the set of contests , and wants to write tasks only for contests in . Each task author cannot write more than one task for the same contest.
There are topics in programming contest tasks, numbered from to . Each task has exactly one topic. The th task author is familiar with the set of topics , and wants to write tasks only about topics in . Each task author cannot write more than one task about the same topic.
Each contest has a syllabus. The th contest syllabus contains the set of topics , and the topic of each task written for the contest must be in . 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 , , ().
The next lines each begin with (), followed by distinct contest numbers (). Each contest number appears at most twice across all .
The next lines each begin with (), followed by distinct topic numbers (). Each topic number appears at most twice across all .
The next lines each begin with (), followed by distinct topic numbers (). Each topic number appears at most twice across all .
Output
Print one integer on a line: the maximum total number of tasks that can be written across all contests.