#P9896. [ICPC2018 Qingdao R] Sub-cycle Graph

    ID: 9286 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>图论2018O2优化组合数学ICPC青岛

[ICPC2018 Qingdao R] Sub-cycle Graph

题目描述

Given an undirected simple graph with nn (n3n \ge 3) vertices and mm edges where the vertices are numbered from 1 to nn, 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 nn vertices.

Given two integers nn and mm, your task is to calculate the number of different sub-cycle graphs with nn vertices and mm edges. As the answer may be quite large, please output the answer modulo 109+710^9+7.

Recall that

  • A simple graph is a graph with no self loops or multiple edges;
  • A simple cycle of nn (n3n \ge 3) vertices is a connected undirected simple graph with nn vertices and nn edges, where the degree of each vertex equals to 2;
  • Two undirected simple graphs with nn vertices and mm edges are different, if they have different sets of edges;
  • Let u<vu < v, we denote (u,v)(u, v) as an undirected edge connecting vertices uu and vv. Two undirected edges (u1,v1)(u_1, v_1) and (u2,v2)(u_2, v_2) are different, if u1u2u_1 \ne u_2 or v1v2v_1 \ne v_2.

输入格式

There are multiple test cases. The first line of the input contains an integer TT (about 2×1042 \times 10^4), indicating the number of test cases. For each test case:

The first and only line contains two integers nn and mm (3n1053 \le n \le 10^5, 0mn(n1)20 \le m \le \frac{n(n-1)}{2}), indicating the number of vertices and the number of edges in the graph.

It's guaranteed that the sum of nn in all test cases will not exceed 3×1073 \times 10^7.

输出格式

For each test case output one line containing one integer, indicating the number of different sub-cycle graphs with nn vertices and mm edges modulo 109+710^9+7.

题目大意

题目描述

对于一个有 n(n3)n(n\ge3) 个点和 mm 条边的无向简单图,其中点的编号为 11nn。如果加非负整数条边能使这个图是变为 nn 个点的简单环,我们称这个是一个 “半环” 图。

给定两个整数 nnmm,你的任务是计算有多少个不同的 nn 个点,mm 条边的 “半环” 图。考虑到答案会很大,请将答案模 109+710^{9} + 7 的结果输出。

定义

  • 一个简单图是指一个没有自环和重边的图;
  • nn 个点的 “简单环” 是指任意一个有 nn 个点和 nn 条边的无向简单连通图,其中所有点的度均为 22
  • 如果两个有着 nn 个点和 mm 条边的无向简单图是不同的,那么它们具有着不同的边集;
  • 现在有两个点 uuv(u<v)v(u < v),记 (u,v)(u,v) 表示连接 u,vu,v 两点的无向边。两条无向边 (u1,v1)(u_1,v_1)(u2,v2)(u_2,v_2) 如果是不同的,那么 u1u2u_1\ne u_2v1v2v_1\ne v_2

输入格式

此题有多组数据。

第一行有一个整数 TT(约为 2×1042\times 10^{4}),指测试用例的数量。对于每组数据:

一组数据只有一行,两个整数 nnmm3n1053 \le n \le 10^{5}0mn(n1)20\le m \le \frac{n(n-1)}{2}),表示图的点数和边数。

nn 的总和不超过 3×1073\times 10^{7}

输出格式

对于每组数据,你只需要输出一行表示答案。

3
4 2
4 3
5 3
15
12
90

提示

The 12 sub-cycle graphs of the second sample test case are illustrated below.