#P1682. 过家家

过家家

Description

There are 2n2n elementary school students playing the “playing house” game: nn boys labeled 11 to nn, and nn girls labeled 11 to nn. Each girl may choose a boy with whom she does not quarrel as her partner. In addition, if girl XX has a friend (also a girl) YY who does not quarrel with boy ZZ, then XX may also choose ZZ. Moreover, friendship is transitive: if aa and bb are friends, and bb and cc are friends, then aa and cc are also considered friends. Note that a boy may be chosen by multiple girls as their partner.

Once every girl has chosen a partner, they start a new round of the game. After each round, every girl looks for a new boy as her partner (one she has never chosen before). Also, each girl may, in total, force at most kk boys to accept her, regardless of whether they have quarreled before.

Your task is to determine the maximum number of rounds the 2n2n students can play.

Input Format

The first line contains four integers n,m,k,fn, m, k, f (Constraints: 3n2503 \le n \le 250, 0<m<n20 < m < n^{2}, 0f<n0 \le f < n).

Here, nn means there are 2n2n students in total, with nn boys and nn girls.

The next mm lines each contain two integers a,ba, b, indicating that girl aa and boy bb have never quarreled.

The next ff lines each contain two integers c,dc, d, indicating that girls cc and dd are friends.

Output Format

For each test, output one integer, the maximum number of rounds the 2n2n students can play.

4 5 1 2
1 1
2 3
3 2
4 2
4 4
1 4
2 3

3

Hint

Translated by ChatGPT 5