#P1037. [NOIP 2002 普及组] 产生数
[NOIP 2002 普及组] 产生数
Description
Given an integer and transformation rules.
Rules:
- A single digit can be transformed into another single digit.
- The right-hand side of a rule cannot be zero.
For example: . There are two rules:
- .
- .
After applying transformations, the integer can produce the following integers (including the original number):
- .
- .
- .
- .
There are distinct generated numbers.
Now, given an integer and rules, determine how many different integers can be produced by applying any number of transformations (zero or more). Only output the count.
Input Format
The first line contains two integers , as described.
The next lines each contain two integers , representing each rule.
Output Format
Output a single line containing the number of distinct integers that can be generated.
234 2
2 5
3 6
4
Hint
Constraints: For of the testdata, , .
Problem Source: NOIP 2002 Junior, Problem 3.
Translated by ChatGPT 5
京公网安备 11011102002149号