포럼
문제 ICPC00180

K. Kitchen Combinatorics

설명

The world-renowned Swedish Chef is planning a gourmet three-course dinner for some muppets: a starter course, a main course, and a dessert. His famous Swedish cook-book offers a wide variety of choices for each of these three courses, though some of them do not go well together (for instance, you of course cannot serve chocolate moose and sooted shreemp at the same dinner).

Each potential dish has a list of ingredients. Each ingredient is in turn available from a few different brands. Each brand is of course unique in its own special way, so using a particular brand of an ingredient will always result in a completely different dinner experience than using another brand of the same ingredient.

Some common ingredients such as pølårber may appear in two of the three chosen dishes, or in all three of them. When an ingredient is used in more than one of the three selected dishes, Swedish Chef will use the same brand of the ingredient in all of them.

While waiting for the meecaroo, Swedish Chef starts wondering: how many different dinner experiences are there that he could make, by different choices of dishes and brands for the ingredients?

제약
입력 형식

The input consists of:
- one line containing five integers \(r\), \(s\), \(m\), \(d\), \(n\), where \(1 \le r \le 1\,000\) is the number of different ingredients that exist, \(1 \le s, m, d \le 25\) are the number of available starter dishes, main dishes, and desserts, respectively, and $0 \le n \le
2\,000$ is the number of pairs of dishes that do not go well together.
- one line containing \(r\) integers \(b_1, \ldots, b_r\), where $1
\le b_i \le 100\( is\ the\ number\ of\ different\ brands\ of\ ingredient \)i$.
- \(s+m+d\) lines describing the \(s\) starter dishes, then the \(m\) main dishes, then the \(d\) desserts. Each such line starts with an integer \(1 \le k \le 20\) denoting the number of ingredients of the dish, and is followed by \(k\) distinct integers \(i_1, \ldots, i_k\), where for each \(1 \le j \le k\), \(1 \le i_j \le r\) is an ingredient.
- \(n\) lines each containing two incompatible dishes. Each dish is identified by an integer \(1 \le j \le s+m+d\), referring to the \(j\)'th dish given in the input (so \(1 \le j \le s\) refers to the starter dishes, \(s < j \le s+m\) refers to the main dishes, and $s+m
< j \le s+m+d$ refers to the desserts).

Each pair of incompatible dishes in the input consists of two dishes of different types, and any one pair of dishes is listed at most once.

출력 형식

If the number of different dinner experiences Swedish Chef can make is at most \(10^{18}\), then output that number. Otherwise, output "too many".

예제 1
입력
6 1 1 1 0
2 3 1 5 3 2
2 1 2
3 3 4 5
1 6
출력
180
예제 2
입력
3 2 2 1 1
2 3 2
1 1
1 2
1 2
1 3
1 1
2 3
출력
22
예제 3
입력
3 1 1 1 1
5 5 5
3 1 2 3
3 1 2 3
3 1 2 3
2 1
출력
0
예제 4
입력
10 1 1 1 0
100 100 100 100 100 100 100 100 100 100
4 1 2 3 4
3 5 6 7
3 8 9 10
출력
too many
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC NWERC 2015

평가 및 의견

K. Kitchen Combinatorics

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 1 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

K. Kitchen Combinatorics

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8