#P3581. [POI 2015 R1] 圆桌巫师 Sorcerers of the Round Table

[POI 2015 R1] 圆桌巫师 Sorcerers of the Round Table

Description

There are nn people (numbered 1n1 \sim n) sitting in a circle around a round table. For any two people sitting in adjacent seats, the absolute difference of their numbers must not exceed pp. Among them, some people dislike others. If aa dislikes bb, then bb cannot sit in the seat immediately to the right of aa. Now, assuming the seat of person nn has been fixed, how many valid seating arrangements are there for the remaining people?

Input Format

The first line contains three integers n,k,pn,k,p (1n1061\le n\le {10}^6, 0k1050\le k\le {10}^5, 0p30\le p\le 3).
The next kk lines each contain two integers ai,bia_i, b_i (1ai,bin1\le a_i, b_i \le n, aibia_i \neq b_i), meaning aia_i dislikes bib_i. The same pair ai,bia_i,b_i will not be repeated.

Output Format

Output a single integer, which is the number of valid arrangements modulo 109+7{10}^9+7.

5 2 3
1 3
5 4
6

Hint

Original title: Czarnoksiężnicy okrągłego stołu.

Translated by ChatGPT 5