日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【PAT - 甲级1094】The Largest Generation (25分)(dfs建树)

發布時間:2023/12/10 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【PAT - 甲级1094】The Largest Generation (25分)(dfs建树) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level belong to the same generation. Your task is to find the generation with the largest population.

Input Specification:

Each input file contains one test case. Each case starts with two positive integers?N?(<100) which is the total number of family members in the tree (and hence assume that all the members are numbered from 01 to?N), and?M?(<N) which is the number of family members who have children. Then?M?lines follow, each contains the information of a family member in the following format:

ID K ID[1] ID[2] ... ID[K]

where?ID?is a two-digit number representing a family member,?K?(>0) is the number of his/her children, followed by a sequence of two-digit?ID's of his/her children. For the sake of simplicity, let us fix the root?ID?to be?01. All the numbers in a line are separated by a space.

Output Specification:

For each test case, print in one line the largest population number and the level of the corresponding generation. It is assumed that such a generation is unique, and the root level is defined to be 1.

Sample Input:

23 13 21 1 23 01 4 03 02 04 05 03 3 06 07 08 06 2 12 13 13 1 21 08 2 15 16 02 2 09 10 11 2 19 20 17 1 22 05 1 11 07 1 14 09 1 17 10 1 18

Sample Output:

9 4

題目大意:

給你一棵樹,讓你找到節點數最多的那個深度和對應的節點個數。

解題報告:

? 按照題意建樹,然后dfs掃一遍得到深度,輸出結果即可。

AC代碼:

#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<stack> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define FF first #define SS second #define ll long long #define pb push_back #define pm make_pair using namespace std; typedef pair<int,int> PII; const int MAX = 2e5 + 5; int n,m; int dep[MAX],cnt[MAX],mx,ans,ansd; vector<int> vv[MAX]; void dfs(int cur,int fa) {dep[cur] = dep[fa] + 1;cnt[dep[cur]]++;mx = max(mx,dep[cur]);int up = vv[cur].size();for(int i = 0; i<up; i++) {int v = vv[cur][i];dfs(v,cur);} } int main() {cin>>n>>m;for(int fa,num,i = 1; i<=m; i++) {scanf("%d%d",&fa,&num);for(int x,j = 1; j<=num; j++) {scanf("%d",&x);vv[fa].pb(x);}}dfs(1,0);for(int i = 1; i<=mx; i++) {if(cnt[i] > ans) {ansd = i;ans = cnt[i];}}printf("%d %d\n",ans,ansd);return 0 ; }

?

總結

以上是生活随笔為你收集整理的【PAT - 甲级1094】The Largest Generation (25分)(dfs建树)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 波多野结衣视频在线 | 亚洲精品福利在线 | 国产精品免费看片 | 日本高清视频www夜色资源 | 亚洲h在线观看 | 不卡视频一区 | 日韩中文字 | 亚洲一区二区视频网站 | 超碰日日夜夜 | 国产精品探花一区二区在线观看 | 九九99精品 | 五月婷婷婷 | 午夜在线观看免费视频 | 亚洲视频区 | 国产三级在线观看 | 中文字幕永久 | 欧美日韩亚洲二区 | 少妇爽 | 成人免费看| 亚洲天堂日韩av | av中文资源网 | 激情福利视频 | 午夜h视频 | 2019国产精品| 羞羞的网站在线观看 | 夜夜草天天干 | 日韩美女视频在线观看 | 国产片一区二区三区 | 色婷婷视频 | 国产又黄又大又粗的视频 | 俄罗斯黄色录像 | 91视频精品 | 精品视频在线免费 | 久久鲁鲁 | 老妇裸体性猛交视频 | 国产精品100| 亚洲第一av| 欧美丰满熟妇bbbbbb百度 | 色窝在线 | 日韩第三页 | 亚洲第一成人网站 | 亚洲AV无码国产精品播放在线 | 在哪里可以看毛片 | 无遮挡又爽又刺激的视频 | 日本少妇色| 亚洲免费自拍 | 国产精品国产三级国产普通话对白 | 日韩精品91 | 色婷婷av一区二区三区大白胸 | 91国偷自产中文字幕久久 | 特色黄色片 | 性涩av | 久久国产激情 | 亚洲美女福利 | 色偷偷视频 | 蜜臀久久99精品久久久画质超高清 | 国产成人综合视频 | 国产精品人八做人人女人a级刘 | 久久精品午夜福利 | 久久精品一二三 | 高h视频在线观看 | 成人精品区 | 九九久久99| 天天色影网 | 看成人片| 国产成人区 | 日韩欧美大陆 | 国产女主播一区二区 | 国产一二三区在线视频 | 白白色视频在线 | 国产精品专区在线观看 | 夜夜嗨av一区二区三区网页 | 视频一区二区视频 | 亚洲成人免费在线视频 | 97爱视频 | 91在线免费观看网站 | 色婷婷av一区二区三区gif | 长篇高h肉爽文丝袜 | 91成人免费网站 | 天天综合中文字幕 | 大陆女明星乱淫合集 | 欧美精品一区二区三区三州 | 婷婷深爱网| 国产女人呻吟高潮抽搐声 | 一区二区中文字幕 | 日本成人激情 | 欧美级毛片 | 国产毛片久久久 | 欧美成人精品一区二区三区在线看 | 日韩精品一区二区在线看 | 五月天色小说 | 69人妻一区二区三区 | 7mav视频| 亚洲一道本 | 深爱开心激情网 | a免费在线 | 男女超碰| 伊人午夜 | 国产日产精品一区二区三区 |