原题:
A 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 and y = 3 .
The snowflake graph above has a central vertex 15 , then x = 5 vertices attached to it ( 33 , 66 , 77 , 88 , and 2020 ), and then y = 3 vertices attached to each of those.
Given a snowflake graph, determine the values of x and y .
题目大意:
给定一个 n 个节点的层数为 3(根节点层数为 1)的树,求根节点的度数和根节点的孩子的孩子数。
考察图的运用。
代码:
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t--)
{
int n,m;
cin>>n>>m;
vector<int> a[205];
while(m--)
{
int x,y;
cin>>x>>y;
a[x].push_back(y);
a[y].push_back(x);
}
int ye=0;
for(int i=0;i<=n;i++)
{
if(a[i].size()==1)
{
ye++;
}
}
int x=n-ye-1,y=ye/x;
cout<<x<<" "<<y<<"\n";
}
return 0;
}