1107. Social Clusters (30)
When register on a social network, you are always asked to specify your hobbies in order to find some potential friends with the same hobbies. A "social cluster" is a set of people who have some of their hobbies in common. You are supposed to find all the clusters.
Input Specification:
Each input file contains one test case. For each test case, the first line contains a positive integer N (<=1000), the total number of people in a social network. Hence the people are numbered from 1 to N. Then N lines follow, each gives the hobby list of a person in the format:
Ki: hi[1] hi[2] ... hi[Ki]
where Ki (>0) is the number of hobbies, and hi[j] is the index of the j-th hobby, which is an integer in [1, 1000].
Output Specification:
For each case, print in one line the total number of clusters in the network. Then in the second line, print the numbers of people in the clusters in non-increasing order. The numbers must be separated by exactly one space, and there must be no extra space at the end of the line.
Sample Input:
8
3: 2 7 10
1: 4
2: 5 3
1: 4
1: 3
1: 4
4: 6 8 1 5
1: 4
Sample Output:
3
4 3 1
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
int ans[][]; bool cmp(int a,int b)
{
return a > b;
} struct node
{
vector<int> child;
}; node Tree[]; int MIN = ;
int cnt = ;
bool vis[];
vector<int> Fun[];
vector<int> stu[];
void DFS(int root,int& sum)
{
for(int i = ;i < stu[root].size();++i)
{
for(int k = ;k < Fun[ stu[root][i] ].size();++k)
{
if(!vis[Fun[ stu[root][i] ][k]])
{
++sum;
vis[Fun[ stu[root][i] ][k]] = ;
DFS(Fun[ stu[root][i] ][k],sum);
}
}
}
} int main()
{
int n,num,tem;
double pri,rate;
scanf("%d",&n);
for(int i = ;i <= n ;++i)
{
scanf("%d",&num);
getchar();
for(int k = ;k < num;++k)
{
scanf("%d",&tem);
Fun[tem].push_back(i);
stu[i].push_back(tem);
}
}
vector<int> vv;
int cnt = ;;
for(int i = ;i <= n ;++i)
{
if(!vis[i])
{
int sum = ;
++cnt;
DFS(i,sum);
vv.push_back(sum);
}
}
sort(vv.begin(),vv.end(),cmp);
printf("%d\n",vv.size());
for(int i = ;i < vv.size();++i)
{
if(i == ) printf("%d",vv[]);
else printf(" %d",vv[i]);
}
printf("\n");
return ;
}
1107. Social Clusters (30)的更多相关文章
- [并查集] 1107. Social Clusters (30)
1107. Social Clusters (30) When register on a social network, you are always asked to specify your h ...
- 1107 Social Clusters (30)(30 分)
When register on a social network, you are always asked to specify your hobbies in order to find som ...
- pat甲级 1107. Social Clusters (30)
When register on a social network, you are always asked to specify your hobbies in order to find som ...
- PAT (Advanced Level) 1107. Social Clusters (30)
简单并查集. #include<cstdio> #include<cstring> #include<cmath> #include<vector> # ...
- PAT甲题题解-1107. Social Clusters (30)-PAT甲级真题(并查集)
题意:有n个人,每个人有k个爱好,如果两个人有某个爱好相同,他们就处于同一个集合.问总共有多少个集合,以及每个集合有多少人,并按从大到小输出. 很明显,采用并查集.vis[k]标记爱好k第一次出现的人 ...
- 【PAT甲级】1107 Social Clusters (30分)(非递归并查集)
题意: 输入一个正整数N(<=1000),表示人数,接着输入N行每行包括一个他的爱好数量:和爱好的序号.拥有相同爱好的人们可以默认他们在同一个俱乐部,输出俱乐部的数量并从大到小输出俱乐部的人数( ...
- PAT甲级——1107 Social Clusters (并查集)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90409731 1107 Social Clusters (30 ...
- PAT-1107 Social Clusters (30 分) 并查集模板
1107 Social Clusters (30 分) When register on a social network, you are always asked to specify your ...
- 1107 Social Clusters[并查集][难]
1107 Social Clusters(30 分) When register on a social network, you are always asked to specify your h ...
随机推荐
- 【JEMTER】后置处理器JSON Path Extractor获取server端返回的json中某项值
需求1:点击所有报表模板时,server端返回所有报表模板的ID(templateId),测试时需要下载某个模板生成的报表 需求2:点击单个报表模板时,server端返回这个报表模板下的所有报表ID( ...
- 使用SourceTree
SourceTree是个git的GUI软件. 教程将“使用Git”那个小节可视化,更为直观. 第一次启动的时候选择忽略,然后直接进入界面. 填入git地址与注册邮箱即可 例如mindset这本书的g ...
- sql语句大全~·留着有用
一.基础 1.说明:创建数据库CREATE DATABASE database-name 2.说明:删除数据库drop database dbname3.说明:备份sql server--- 创建 备 ...
- HDU 4424 Conquer a New Region
http://acm.hdu.edu.cn/showproblem.php?pid=4424 [题目大意] 给你N个点和N-1条边的连通图,也就是说任意两点间的路径是唯一的.每条边有个权值,从一点到另 ...
- 剑指Offer34 数组中的逆序对
/************************************************************************* > File Name: 34_Invers ...
- SQL---------表的约束
表的约束 防止同一条数据完全重复:主键约束(primary key)唯一键约束(unique),自增长: 防止数据为空: 非空约束(not noll),默认值: 防止乱填数据: 外键, 定义数据类型, ...
- JDK 自带工具试用(一)
简述: 运维监控会用到JDK的小工具 说明: 1. jps 用来查看当前运行的Java进程 我在eclipse中起了一个web 应用 或者用jps -l 可以查看的更清楚一点 jps -v 看到103 ...
- ASP.Net 验证控件 RegularExpressionValidator
定义和用法 RegularExpressionValidator 控件用于验证输入值是否匹配指定的模式. 注释:除非浏览器不支持客户端验证或 EnableClientScript 属性被设置为 fal ...
- 博客不再更新,已转移到自己的小站iwenku.net
博客不再更新,已转移到自己的小站iwenku.net,欢迎访问! 博客不再更新,已转移到自己的小站iwenku.net,欢迎访问! 博客不再更新,已转移到自己的小站iwenku.net,欢迎访问! 博 ...
- iOS - OC & Xcode
一.入门 1.1 iOS模版介绍 1.2 简单工程项目 1.3 设置App启动的设备方向 1.4 Xcode界面介绍 1.5 快速查找文件 1.6 快速更改同名变量 1.7 将代码提取为方法 1.8 ...