PAT 1094. The Largest Generation (25)
来源:互联网 发布:mac最新远程windows 编辑:程序博客网 时间:2024/05/24 06:46
与六度空间相似 更简单一些
#include<vector>#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<string>
#include<set>
#include<stack>
using namespace std;
int main()
{
vector<int> v[101];
int a[101]={0};
int sum[101]={0};
int m,n;
scanf("%d%d",&n,&m);
int index ,sonnum,son;
for(int i=0;i<m;i++)
{
scanf("%d%d",&index,&sonnum);
for(int j=0;j<sonnum;j++)
{
scanf("%d",&son);
v[index].push_back(son);
a[son]=1;
}
}
int root;
int num=1;
for(int i=1;i<=n;i++)
if(!a[i])
{
root=i;
break;
}
queue<int> q;
q.push(root);
q.push(-1);
int t;
int MAX=0;
while(!q.empty()){
t=q.front();
if(t!=-1)
sum[num]++;
q.pop();
if(t==-1)
{
num++;
continue;
}
for(int i=0;i<v[t].size();i++)
{
q.push(v[t][i]);
}
if(sum[num]>MAX)
{
index=num;
MAX=sum[num];
}
if(q.front()==-1)
q.push(-1);
}
printf("%d %d\n",MAX,index);
return 0;
}
0 0
- PAT A 1094. The Largest Generation (25)
- PAT 1094. The Largest Generation (25)
- PAT 1094. The Largest Generation (25)
- PAT 1094. The Largest Generation (25)
- 【PAT】1094. The Largest Generation (25)
- PAT 1094. The Largest Generation (25)
- pat-1094. The Largest Generation (25)
- PAT(A) - 1094. The Largest Generation (25)
- 1094. The Largest Generation (25) PAT甲级
- PAT 1094. The Largest Generation (25)
- PAT-A-1094. The Largest Generation (25)
- pat-a 1094. The Largest Generation (25)
- PAT A 1094. The Largest Generation (25)
- Pat(A) 1094. The Largest Generation (25)
- PAT 甲级 1094. The Largest Generation (25)
- PAT 1094. The Largest Generation
- PAT 1094. The Largest Generation
- PAT--1094. The Largest Generation
- 哈希快速检索之三种海明空间中的检索方法
- 网络协议学习笔记-数据链路层-MTU、路径MTU和串行线路吞吐量计算
- 20151201 ocp 卷3 1-30
- ElasticSearch学习3_elasticsearch集群管理工具head插件
- dom4j解析和生成XML文件
- PAT 1094. The Largest Generation (25)
- 如何利用QT设计师设计的ui生成相应头文件
- IOS的一些手势方法(手势的tag值 绝对值 偏移量 中心点 等等)
- 将tomcat注册为windows服务
- Xcode安装VVDocumenter文档注释插件
- 初来乍到
- GitHub上搭建Hexo个人博客
- Java--length,length(),size()区别
- win10设置为CentOS 7的默认启动项