Forever Winter题解

本文介绍了一种名为雪崩图的特殊图结构,通过两个大于11的整数x和y构建。给定一个三层树,目标是确定根节点的度数(连接的边数)和根节点的孩子的孩子数。代码展示了如何使用图论算法解决这个问题。
摘要由CSDN通过智能技术生成

原题:

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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值