当前位置:网站首页>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;
}边栏推荐
- Wechat applet waterfall flow and pull up to the bottom
- 带有注意力RPN和多关系检测器的小样本目标检测网络(提供源码和数据及下载)...
- Leetcode simple question: check whether the array is sorted and rotated
- stm32逆向入门
- Mobile terminal - uniapp development record (public request encapsulation)
- Distinguish between releases and snapshots in nexus private library
- Interface frequency limit access
- 7. Integrated learning
- I stepped on a foundation pit today
- Esp32-c3 learning and testing WiFi (II. Wi Fi distribution - smart_config mode and BlueIf mode)
猜你喜欢

Leetcode simple problem delete an element to strictly increment the array
![[USACO 2009 Dec S]Music Notes](/img/e6/282a8820becdd24d63dcff1b81fcaf.jpg)
[USACO 2009 Dec S]Music Notes

并发操作-内存交互操作

Review the configuration of vscode to develop golang

stm32逆向入门

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

Coordinatorlayout appbarrayout recyclerview item exposure buried point misalignment analysis

Do you know UVs in modeling?

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

The reason why the entity class in the database is changed into hump naming
随机推荐
Coordinatorlayout appbarrayout recyclerview item exposure buried point misalignment analysis
Leetcode simple question: check whether two string arrays are equal
Prepare for 2022 and welcome the "golden three silver four". The "summary of Android intermediate and advanced interview questions in 2022" is fresh, so that your big factory interview can go smoothly
Market status and development prospect forecast of global heat curing adhesive industry in 2022
Three representations of signed numbers: original code, inverse code and complement code
Problems encountered in fuzzy query of SQL statements
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
Web security - CSRF (token)
Thesis reading_ ICD code_ MSMN
Sdl2 + OpenGL glsl practice (Continued)
Leetcode simple question: check whether the string is an array prefix
论文阅读_清华ERNIE
Uipath practice (08) - selector
Handling record of electric skateboard detained by traffic police
On typescript and grammar
The current market situation and development prospect of the global gluten tolerance test kit industry in 2022
document. The problem of missing parameters of referer is solved
MPM model and ab pressure test
[SQL injection point] location and judgment of the injection point
Current market situation and development prospect forecast of the global fire boots industry in 2022