题目描述
Problem Description
Takahashi bought a paint called "Nurimamasu" as a prize for ranking high in a competition.
Takahashi also has a directed graph with $ N $ vertices, where each vertex is represented as vertex $ 1 $, vertex $ 2 $, ..., vertex $ N $.
Takahashi loves painting so much that he wants to use the "Nurimamasu" to paint the vertices of his directed graph. However, painting randomly is not interesting, so he will paint the vertices under the following constraints between some vertices:
- Type 1: When painting a vertex $ x $, vertex $ y $ must already be painted.
- Type 2: When painting a vertex $ u $, vertex $ v $ must not be painted.
There are $ A $ Type 1 constraints and $ B $ Type 2 constraints.
Initially, no vertices are painted. Your task is to determine the maximum number of vertices that can be painted under these constraints by painting them in an appropriate order.
Input Format
The input is given from the standard input in the following format:
$ N $ $ A $ $ x_1 $ $ y_1 $ $ x_2 $ $ y_2 $ : $ x_A $ $ y_A $ $ B $ $ u_1 $ $ v_1 $ $ u_2 $ $ v_2 $ : $ u_B $ $ v_B $
- The first line contains an integer $N\ (1≦N≦100)$, representing the number of vertices in the graph.
- The second line contains an integer $A\ (0≦A≦100)$, representing the number of Type 1 constraints.
- The next $ A $ lines contain the information of Type 1 constraints. The $i\ (1≦i≦A)$ line contains two integers $ x_i,y_i(1≦x_i,y_i≦N,x_i≠y_i) $, representing the constraint that vertex $ x_i $ can only be painted if vertex $ y_i $ is already painted.
- The line following the last Type 1 constraint contains an integer $B\ (0≦B≦10)$, representing the number of Type 2 constraints.
- The next $ B $ lines contain the information of Type 2 constraints. The $i\ (1≦i≦B)$ line contains two integers $ u_i,v_i(1≦u_i,v_i≦N,u_i≠v_i) $, representing the constraint that vertex $ u_i $ cannot be painted if vertex $ v_i $ is already painted.
- It is possible that under these constraints, some vertices may never be able to be painted, and there may be multiple identical constraints.
Output Format
Output the maximum number of vertices that can be painted under these constraints. The output should end with a newline.
Sample Input and Output
Sample Input #1
3
2
1 2
2 3
1
3 1
Sample Output #1
3
Sample Input #2
3
2
1 2
2 3
1
1 3
Sample Output #2
2
Sample Input #3
3
3
1 2
2 3
3 1
0
Sample Output #3
0
Sample Input #4
9
7
1 2
1 3
5 4
8 5
9 8
6 1
7 1
2
1 4
4 1
Sample Output #4
6
Sample Input #5
100
0
0
Sample Output #5
100
Notes/Hints
Sample Explanation 1
It is good to paint vertex 3 → vertex 2 → vertex 1 in order.
Sample Explanation 2
Under these constraints, vertex 1 cannot be painted.
Sample Explanation 3
Under these constraints, no vertices can be painted.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分