DreamGrid has just found an undirected simple graph with $n$ vertices and no edges (that's to say, i

本文介绍了一种在无向简单图上进行操作和查询的方法,包括连接顶点和查询添加新边后连通分量的可能最小和最大数量。通过一系列操作,探讨了图的连通性和变化趋势。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

1 a b – Connect the aaa-th vertex and the bbb-th vertex by an edge. It’s guaranteed that before this operation, there does not exist an edge which connects vertex aaa and bbb directly.
2 k – Find the answer for the query: What’s the minimum and maximum possible number of connected components after adding kkk new edges to the graph. Note that after adding the kkk 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 TTT, indicating the number of test cases. For each test case:

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

For the following qqq lines, the iii-th line first contains an integer pip_ipi (pi∈{1,2}p_i \in \{1, 2\}pi{1,2}), indicating the type of the iii-th operation.

If pi=1p_i = 1pi=1, two integers aia_iai and bib_ibi follow (1≤ai,bi≤n1 \le a_i, b_i \le n1ai,bin, ai≠bia_i \ne b_iai=bi), indicating an operation of the first type. It’s guaranteed that before this operation, there does not exist an edge which connects vertex aaa and bbb directly.
If pi=2p_i = 2pi=2, one integer kik_iki follows (0≤ki≤n(n−1)20 \le k_i \le \frac{n(n-1)}{2}0ki2n(n1)), indicating an operation of the second type. It’s guaranteed that after adding kik_iki edges to the graph, the graph is still possible to be a simple graph.
It’s guaranteed that the sum of nnn in all test cases will not exceed 10610^6106, and the sum of qqq in all test cases will not exceed 2×1062 \times 10^62×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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值