You are given a small undirected graph with n vertices (numbered 1..n) and m edges, and an integer k. A proper k-coloring assigns each vertex one of k colors (numbered 1..k) such that every edge connects two vertices of different colors.
Count the number of distinct proper k-colorings of the graph. Since this count can be large, print it modulo 1,000,000,007.
Line 1: three integers n, m, and k.
Next m lines: two integers u v (1-indexed) — an undirected edge between vertex u and vertex v.
A single integer: the number of proper k-colorings, modulo 1,000,000,007.
Example 1
Input
3 3 3 1 2 1 3 2 3
Expected
6
Explanation
The 3 vertices form a triangle where every pair is connected, so all three must get different colors; with 3 colors available there are 3x2x1=6 proper colorings.
Example 2
Input
2 0 2
Expected
4
Explanation
With no edges, each of the 2 vertices can independently take any of the 2 colors, giving 2x2=4 colorings.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →