QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 256 MB 總分: 100

#7818. Life by the rules

统计

A malicious computer science teacher has decided to introduce special rules for creating nicknames on the school website. He has set a collection of rules of the form "A B", which means that the character B can follow the character A. A nickname can be any valid sequence of characters of length exactly K. A nickname can be any sequence of characters where each character, except for the first one, can follow the previous one according to the rules, and the first character can be any character from the given alphabet. Determine the total number of unique nicknames that can be formed according to the given rules.

Input

The first line contains three integers $N$, $M$, and $K$, where $N$ is the number of characters in the alphabet, $1 \le N \le 5000$, $M$ is the number of rules, $0 \le M \le 5000$, and $K$ is the specified length of the nickname, $1 \le K \le 5000$. The following $M$ lines each contain two space-separated natural numbers representing the indices (starting from 1) of the alphabet characters.

Output

A single non-negative integer — the number of valid nicknames of length $K$, taken modulo $10^9 + 7$.

Examples

Input 1

2 3 4
1 1
1 2
2 2

Output 1

5

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.