当前位置:网站首页>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;
}边栏推荐
- Market status and development prospects of the global automatic tea picker industry in 2022
- Market status and development prospects of the global autonomous marine glider industry in 2022
- Handling record of electric skateboard detained by traffic police
- Shell script -- condition judgment
- [develop wechat applet local storage with uni app]
- "Niuke brush Verilog" part II Verilog advanced challenge
- Market status and development prospect prediction of the global fire extinguisher industry in 2022
- Introduction to message queuing (MQ)
- Introduction to JVM principle
- Symbol of array element product of leetcode simple problem
猜你喜欢

Number of uniform strings of leetcode simple problem
![[set theory] relationship properties (symmetry | symmetry examples | symmetry related theorems | antisymmetry | antisymmetry examples | antisymmetry theorems)](/img/34/d195752992f8955bc2a41b4ce751db.jpg)
[set theory] relationship properties (symmetry | symmetry examples | symmetry related theorems | antisymmetry | antisymmetry examples | antisymmetry theorems)

Network security textual research recommendation

Kept hot standby and haproxy

String matching: find a substring in a string

论文阅读_中文医疗模型_ eHealth
![[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

5-36v input automatic voltage rise and fall PD fast charging scheme drawing 30W low-cost chip
![[research materials] 2021 annual report on mergers and acquisitions in the property management industry - Download attached](/img/95/833f5ec20207ee5d7e6cdfa7208c5e.jpg)
[research materials] 2021 annual report on mergers and acquisitions in the property management industry - Download attached

联发科技2023届提前批IC笔试(题目)
随机推荐
Concurrent operation memory interaction
Keepalived热备与HAProxy
Market status and development prospect forecast of global heat curing adhesive industry in 2022
Learning record of arouter principle
Notes | numpy-11 Array operation
Compile and decompile GCC common instructions
Thesis reading_ Chinese NLP_ ELECTRA
Coordinatorlayout appbarrayout recyclerview item exposure buried point misalignment analysis
7. Integrated learning
The reason why the entity class in the database is changed into hump naming
MC Layer Target
【PHP漏洞-弱类型】基础知识、php弱相等、报错绕过
Huawei personally ended up developing 5g RF chips, breaking the monopoly of Japan and the United States
Market status and development prospect forecast of global button dropper industry in 2022
C language self-made Games: Sanzi (tic tac toe chess) intelligent chess supplement
Cross platform plug-in flutter for displaying local notifications_ local_ notifications
The current market situation and development prospect of the global gluten tolerance test kit industry in 2022
[luatos sensor] 1 light sensing bh1750
Market status and development prospects of the global automatic tea picker industry in 2022
ZABBIX monitoring of lamp architecture (3): zabbix+mysql (to be continued)