当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

2888:Magic Bracelet

题目描述

Ginny’s birthday is coming soon. Harry Potter is preparing a birthday present for his new girlfriend. The present is a magic bracelet which consists of n magic beads. The are m kinds of different magic beads. Each kind of beads has its unique characteristic. Stringing many beads together a beautiful circular magic bracelet will be made. As Harry Potter’s friend Hermione has pointed out, beads of certain pairs of kinds will interact with each other and explode, Harry Potter must be very careful to make sure that beads of these pairs are not stringed next to each other.

There infinite beads of each kind. How many different bracelets can Harry make if repetitions produced by rotation around the center of the bracelet are neglected? Find the answer taken modulo 9973.

输入解释

The first line of the input contains the number of test cases.

Each test cases starts with a line containing three integers n (1 n ≤ 109, gcd(n, 9973) = 1), m (1 ≤ m ≤ 10), k (1 ≤ km(m − 1) ⁄ 2). The next k lines each contain two integers a and b (1 ≤ a, b m), indicating beads of kind a cannot be stringed to beads of kind b.

输出解释

Output the answer of each test case on a separate line.

输入样例
4
3 2 0
3 2 1
1 2
3 2 2
1 1
1 2
3 2 3
1 1
1 2
2 2
输出样例
4
2
1
0

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-2888

最后修改于 2020-10-29T06:46:46+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000 131072