Forever Winter

 Forever Winter
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

snowflake graph is generated from two integers x and y, both greater than 11, 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=5 and y=3=3.

The snowflake graph above has a central vertex 1515, then x=5=5 vertices attached to it (33, 66, 77, 88, and 2020), and then y=3=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 (1t10001≤≤1000) — the number of test cases.

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

The next m lines each contain two integers each u and v (1u,vn1≤,≤, uv≠) — 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 11.

Output

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

Example
input
Copy
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
output
Copy
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> //#define int long long using namespace std; const int N=1e5+10,mod=1e9+7; string s; int n,t,a[N],f[N],res,num,ans,m; bool vis; vector<int>g[500]; int main() { std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin>>t; while(t--){ cin>>n>>m; memset(f,0,sizeof f); for(int i=1;i<=n;i++) g[i].clear(); res=ans=0; for(int i=0;i<m;i++){ int u,v; cin>>u>>v; g[v].push_back(u),f[u]++; g[u].push_back(v),f[v]++; } for(int i=1;i<=n;i++){//只需要找到一个所有的子节点都不是1的点就可以 if(f[i]==1) continue; vis=true; for(auto v:g[i]) if(f[v]==1){ vis=false; break; } if(vis){ res=f[i],ans=f[g[i][0]]-1; break; } } cout<<res<<" "<<ans<<endl;; } return 0; }
复制代码

 


__EOF__

本文作者Sakurajimamai
本文链接https://www.cnblogs.com/o-Sakurajimamai-o/p/17517686.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   o-Sakurajimamai-o  阅读(34)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
-- --
点击右上角即可分享
微信分享提示