当前位置:网站首页>1107 social clusters (30 points)
1107 social clusters (30 points)
2022-07-03 04:55:00 【vs5】
The main idea of the topic : Everyone likes some hobbies , Those who have the same hobbies are considered as a group , Number of output groups , And the number of people in each group , From large to small output .
Transform the meaning of the question to find the number of connected blocks , And the number of points in the block . Don't mix the hobby number with the person number here , We mark our hobbies with human labels , Then there is the merge set template .
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 1000;
int p[N],st[N];
int find(int x)
{
if(p[x] != x) p[x] = find(p[x]);
return p[x];
}
int main()
{
int n;
scanf("%d",&n);
for(int i = 1; i <= n; i ++) p[i] = i;
for(int i = 1; i <= n; i ++)
{
int k;
scanf("%d:",&k);
for(int j = 0 ; j < k; j ++)
{
int x;
cin >> x;
if(!st[x]) st[x] = i;// The number is i People like it j This activity
int a = find(i),b = find(st[x]);
if(a != b) p[a] = b;
}
}
vector<int>ans(n + 1,0);int cnt = 0;
for(int i = 1; i <= n; i ++) ans[find(i)] ++;
for(auto it : ans) if(it != 0) cnt ++;
sort(ans.begin(),ans.end(),[](int a,int b)
{
return a > b;
});
cout << cnt << '\n';
for(int i = 0; i < cnt; i ++)
{
if(i != 0) cout << ' ';
cout << ans[i];
}
return 0;
}边栏推荐
- What is UUID
- [PCL self study: filtering] introduction and use of various filters in PCL (continuously updated)
- [research materials] 2021 annual report on mergers and acquisitions in the property management industry - Download attached
- 并发操作-内存交互操作
- Learning practice: comprehensive application of cycle and branch structure (I)
- Compile and decompile GCC common instructions
- Shell script -- condition judgment
- Review the old and know the new: Notes on Data Science
- Day 51 - tree problem
- Market status and development prospects of the global automatic tea picker industry in 2022
猜你喜欢

关于开学的准备与专业认知

M1 Pro install redis

UiPath实战(08) - 选取器(Selector)
![[research materials] annual report of China's pension market in 2021 - Download attached](/img/24/622aeeb38de16ac84128b362ceeddb.jpg)
[research materials] annual report of China's pension market in 2021 - Download attached

LVS load balancing cluster of efficient multi-purpose cluster (NAT mode)

论文阅读_清华ERNIE
![[Yu Yue education] basic reference materials of interchangeability and measurement technology of Zhongyuan Institute of Technology](/img/f1/d0dc4dc3fe49a2d2cd9e452a0ce31e.jpg)
[Yu Yue education] basic reference materials of interchangeability and measurement technology of Zhongyuan Institute of Technology

Online VR model display - 3D visual display solution

data2vec! New milestone of unified mode

The consumption of Internet of things users is only 76 cents, and the price has become the biggest obstacle to the promotion of 5g industrial interconnection
随机推荐
Messy change of mouse style in win system
Small sample target detection network with attention RPN and multi relationship detector (provide source code, data and download)
Online VR model display - 3D visual display solution
Esp32-c3 learning and testing WiFi (II. Wi Fi distribution - smart_config mode and BlueIf mode)
First + only! Alibaba cloud's real-time computing version of Flink passed the stability test of big data products of the Institute of ICT
Leetcode simple question: check whether the string is an array prefix
Introduction to message queuing (MQ)
Thesis reading_ ICD code_ MSMN
ZABBIX monitoring of lamp architecture (2): ZABBIX basic operation
Thesis reading_ Tsinghua Ernie
Hj35 serpentine matrix
[research materials] 2021 China's game industry brand report - Download attached
Current market situation and development prospect forecast of the global fire boots industry in 2022
[Yu Yue education] basic reference materials of interchangeability and measurement technology of Zhongyuan Institute of Technology
Mount NFS in kubesphere
Market status and development prospect prediction of global fermentation acid industry in 2022
Truncated sentences of leetcode simple questions
Cross platform plug-in flutter for displaying local notifications_ local_ notifications
The programmer resigned and was sentenced to 10 months for deleting the code. JD came home and said that it took 30000 to restore the database. Netizen: This is really a revenge
Huawei personally ended up developing 5g RF chips, breaking the monopoly of Japan and the United States