我是靠谱客的博主 任性保温杯,最近开发中收集的这篇文章主要介绍DreamGrid has just found an undirected simple graph with $n$ vertices and no edges (that's to say, i,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

DreamGrid has just found an undirected simple graph with n n n vertices and no edges (that’s to say, it’s a graph with n n n isolated vertices) in his right pocket, where the vertices are numbered from 1 to n n n. Now he would like to perform q q q operations of the following two types on the graph:

1 a b – Connect the a a a-th vertex and the b b b-th vertex by an edge. It’s guaranteed that before this operation, there does not exist an edge which connects vertex a a a and b b b directly.
2 k – Find the answer for the query: What’s the minimum and maximum possible number of connected components after adding k k k new edges to the graph. Note that after adding the k k k edges, the graph must still be a simple graph, and the query does NOT modify the graph.
Please help DreamGrid find the answer for each operation of the second type. Recall that a simple graph is a graph with no self loops or multiple edges.

Input
There are multiple test cases. The first line of the input is an integer T T T, indicating the number of test cases. For each test case:

The first line contains two integers n n n and q q q ( 1 ≤ n ≤ 1 0 5 1 le n le 10^5 1n105, 1 ≤ q ≤ 2 × 1 0 5 1 le q le 2 times 10^5 1q2×105), indicating the number of vertices and the number of operations.

For the following q q q lines, the i i i-th line first contains an integer p i p_i pi ( p i ∈ { 1 , 2 } p_i in {1, 2} pi{1,2}), indicating the type of the i i i-th operation.

If p i = 1 p_i = 1 pi=1, two integers a i a_i ai and b i b_i bi follow ( 1 ≤ a i , b i ≤ n 1 le a_i, b_i le n 1ai,bin, a i ≠ b i a_i ne b_i ai=bi), indicating an operation of the first type. It’s guaranteed that before this operation, there does not exist an edge which connects vertex a a a and b b b directly.
If p i = 2 p_i = 2 pi=2, one integer k i k_i ki follows ( 0 ≤ k i ≤ n ( n − 1 ) 2 0 le k_i le frac{n(n-1)}{2} 0ki2n(n1)), indicating an operation of the second type. It’s guaranteed that after adding k i k_i ki edges to the graph, the graph is still possible to be a simple graph.
It’s guaranteed that the sum of n n n in all test cases will not exceed 1 0 6 10^6 106, and the sum of q q q in all test cases will not exceed 2 × 1 0 6 2 times 10^6 2×106.

Output
For each operation of the second type output one line containing two integers separated by a space, indicating the minimum and maximum possible number of connected components in this query.

Sample Input
1
5 5
1 1 2
2 1
1 1 3
2 1
2 3
Sample Output
3 3
2 3
1 2

最后

以上就是任性保温杯为你收集整理的DreamGrid has just found an undirected simple graph with $n$ vertices and no edges (that's to say, i的全部内容,希望文章能够帮你解决DreamGrid has just found an undirected simple graph with $n$ vertices and no edges (that's to say, i所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(35)

评论列表共有 0 条评论

立即
投稿
返回
顶部