当前位置:网站首页>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 prospect prediction of global colorimetric cup cover industry in 2022
- 雇佣收银员(差分约束)
- 【SQL注入】联合查询(最简单的注入方法)
- Problems encountered in fuzzy query of SQL statements
- 论文阅读_中文医疗模型_ eHealth
- Triangular rasterization
- Notes | numpy-07 Slice and index
- 7. Integrated learning
- 【XSS绕过-防护策略】理解防护策略,更好的绕过
- Wechat applet distance and map
猜你喜欢

I stepped on a foundation pit today

Network security textual research recommendation

Source insight garbled code solution

MPM model and ab pressure test

Mobile terminal - uniapp development record (public request encapsulation)

Truncated sentences of leetcode simple questions

ZABBIX monitoring of lamp architecture (3): zabbix+mysql (to be continued)

Career planning of counter attacking College Students

【XSS绕过-防护策略】理解防护策略,更好的绕过

The usage of micro service project swagger aggregation document shows all micro service addresses in the form of swagger grouping
随机推荐
Leetcode simple problem delete an element to strictly increment the array
Problems encountered in fuzzy query of SQL statements
并发操作-内存交互操作
[tools run SQL blind note]
Career planning of counter attacking College Students
Current market situation and development prospect prediction of global direct energy deposition 3D printer industry in 2022
Silent authorization login and registration of wechat applet
MySQL winter vacation self-study 2022 12 (3)
Market status and development prospect forecast of global heat curing adhesive industry in 2022
[clock 223] [binary tree] [leetcode high frequency]: 102 Sequence traversal of binary tree
论文阅读_中文医疗模型_ eHealth
Notes | numpy-08 Advanced index
Preparation for school and professional cognition
Leetcode simple question: the key with the longest key duration
Online VR model display - 3D visual display solution
[set theory] relation properties (reflexivity | reflexivity theorem | reflexivity | reflexivity theorem | example)
Actual combat 8051 drives 8-bit nixie tube
Current market situation and development prospect forecast of global UV sensitive resin 3D printer industry in 2022
I stepped on a foundation pit today
Leetcode simple question: check whether two string arrays are equal