F. Forever Winter

F. Forever Winter
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
A snowflake graph is generated from two integers x
and y
, both greater than 1
, as follows:

Start with one central vertex.
Connect x
new vertices to this central vertex.
Connect y
new vertices to each of these x
vertices.
For example, below is a snowflake graph for x=5
and y=3
.

The snowflake graph above has a central vertex 15
, then x=5
vertices attached to it (3
, 6
, 7
, 8
, and 20
), and then y=3
vertices attached to each of those.

Given a snowflake graph, determine the values of x
and y
.
Input
The first line contains a single integer t
(1≤t≤1000
) — the number of test cases.

The first line of each test case contains two integers n
and m
(2≤n≤200
; 1≤m≤min(1000,n(n−1)2)
) — the number of vertices and edges in the graph, respectively.

The next m
lines each contain two integers each u
and v
(1≤u,v≤n
, u≠v
) — the numbers of vertices connected by an edge. The graph does not contain multiple edges and self-loops.

It is guaranteed that this graph is a snowflake graph for some integers x
and y
both greater than 1
.

Output
For each test case, on a separate line output the values of x
and y
, in that order, separated by a space.

Example
inputCopy
3
21 20
21 20
5 20
13 20
1 3
11 3
10 3
4 8
19 8
14 8
9 7
12 7
17 7
18 6
16 6
2 6
6 15
7 15
8 15
20 15
3 15
7 6
1 2
1 3
2 4
2 5
3 6
3 7
9 8
9 3
3 6
6 2
2 1
5 2
2 7
4 3
3 8
outputCopy
5 3
2 2
2 3
Note
The first test case is pictured in the statement. Note that the output 3 5 is incorrect, since x
should be output before y
.

#include<bits/stdc++.h>
using namespace std;
const int N = 1010;
int cnt[N];
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		int n, m;
		cin >> n >> m;
		memset(cnt, 0, sizeof cnt);
		for (int i = 0; i < m; i++)
		{
			int u, v;
			cin >> u >> v;
			cnt[u]++, cnt[v]++;//存度数
		}
		map<int, int> cnts;
		for (int i = 1; i <= n; i++)
			cnts[cnt[i]]++;//存每个度数对应点数
		vector<int> v;
		for (auto k : cnts)
			v.push_back(k.second);//每一层的点的个数
		/*
		*   当x!=y
			最里层为1
			中间层为x
			最外层为xy
			else
			x==y
			最里层为1
			v中只有v[0]x+1,v[1](x+1)y
		*/
		sort(v.begin(), v.end());
		if (v.size() == 3) {
			cout << v[1] << ' ' << v[2] / v[1] << '\n';
		}
		else {
			cout << v[0] - 1 << ' ' << v[1] / (v[0] - 1) << '\n';
		}
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值