#P9896. [ICPC2018 Qingdao R] Sub-cycle Graph
[ICPC2018 Qingdao R] Sub-cycle Graph
题目描述
Given an undirected simple graph with () vertices and edges where the vertices are numbered from 1 to , we call it a sub-cycle
graph if it's possible to add a non-negative number of edges to it and turn the graph into exactly one simple cycle of vertices.
Given two integers and , your task is to calculate the number of different sub-cycle graphs with vertices and edges. As the answer may be quite large, please output the answer modulo .
Recall that
- A simple graph is a graph with no self loops or multiple edges;
- A simple cycle of () vertices is a connected undirected simple graph with vertices and edges, where the degree of each vertex equals to 2;
- Two undirected simple graphs with vertices and edges are different, if they have different sets of edges;
- Let , we denote as an undirected edge connecting vertices and . Two undirected edges and are different, if or .
输入格式
There are multiple test cases. The first line of the input contains an integer (about ), indicating the number of test cases. For each test case:
The first and only line contains two integers and (, ), indicating the number of vertices and the number of edges in the graph.
It's guaranteed that the sum of in all test cases will not exceed .
输出格式
For each test case output one line containing one integer, indicating the number of different sub-cycle graphs with vertices and edges modulo .
题目大意
题目描述
对于一个有 个点和 条边的无向简单图,其中点的编号为 到 。如果加非负整数条边能使这个图是变为 个点的简单环,我们称这个是一个 “半环” 图。
给定两个整数 和 ,你的任务是计算有多少个不同的 个点, 条边的 “半环” 图。考虑到答案会很大,请将答案模 的结果输出。
定义
- 一个简单图是指一个没有自环和重边的图;
- 个点的 “简单环” 是指任意一个有 个点和 条边的无向简单连通图,其中所有点的度均为 ;
- 如果两个有着 个点和 条边的无向简单图是不同的,那么它们具有着不同的边集;
- 现在有两个点 和 ,记 表示连接 两点的无向边。两条无向边 和 如果是不同的,那么 或 。
输入格式
此题有多组数据。
第一行有一个整数 (约为 ),指测试用例的数量。对于每组数据:
一组数据只有一行,两个整数 和 (,),表示图的点数和边数。
的总和不超过 。
输出格式
对于每组数据,你只需要输出一行表示答案。
3
4 2
4 3
5 3
15
12
90
提示
The 12 sub-cycle graphs of the second sample test case are illustrated below.