当前位置:网站首页>L2-024 tribe (25 points)
L2-024 tribe (25 points)
2022-04-23 13:57:00 【Heigu Xiaojian】
The question :
In a community , Everyone has their own small circle , It may also belong to many different circles of friends at the same time . We think that friends of friends are all included in a tribe , So I want you to count , In a given community , How many different tribes are there ? And check if any two people belong to the same tribe .
Ideas :
A very naked and check the collection , Note that after connecting the edges, traverse again to make sure that the edges are connected , Then continue the query operation
Code :
#include<bits/stdc++.h>
#include<sstream>
#include<unordered_map>
#define endl '\n'
using namespace std;
const int maxn=10005;
int p[maxn],a[maxn];
int findx(int x)
{
if(p[x]!=x)
{
return p[x]=findx(p[x]);
}
else {
return p[x];
}
}
unordered_map<int ,int >mo;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int n,i,j,k,t,cnt=0,cnt1=0,q;
cin>>n;
for(i=1;i<maxn;i++) p[i]=i;
for(i=0;i<n;i++)
{
cin>>k;
int t=-1,d;
for(j=0;j<k;j++)
{
cin>>d;
if(mo[d]==0){
mo[d]++;
cnt++;
}
if(t==-1) {
t=d;
}
else {
int m1=findx(t);
int m2=findx(d);
if(m1!=m2)
{
p[m2]=m1;
}
}
}
}
mo.clear();
for(i=1;i<=cnt;i++)
{
p[i]=findx(p[i]);
if(mo[p[i]]==0) cnt1++;
mo[p[i]]++;
}
cin>>q;
cout<<cnt<<" "<<cnt1<<endl;
for(i=0;i<q;i++)
{
int u,v;
cin>>u>>v;
if(findx(u)!=findx(v))
{
cout<<"N"<<endl;
}
else {
cout<<"Y"<<endl;
}
}
return 0;
}
版权声明
本文为[Heigu Xiaojian]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231347361092.html
边栏推荐
- Express②(路由)
- Decentralized Collaborative Learning Framework for Next POI Recommendation
- AtCoder Beginner Contest 248C Dice Sum (生成函数)
- AttributeError: ‘dict‘ object has no attribute ‘iteritems‘
- Kettle--控件解析
- Express middleware ③ (custom Middleware)
- try --finally
- Get the attribute value difference between two different objects with reflection and annotation
- Quartus Prime硬件实验开发(DE2-115板)实验一CPU指令运算器设计
- freeCodeCamp----arithmetic_ Arranger exercise
猜你喜欢
神经元与神经网络
JS brain burning interview question reward
Oracle alarm log alert Chinese trace and trace files
记录一个奇怪的bug:缓存组件跳转之后出现组件复制
淘宝发布宝贝提示“您的消保保证金额度不足,已启动到期保障”
【报名】TF54:工程师成长地图与卓越研发组织打造
MySQL index [data structure + index creation principle]
Detailed explanation of redis (Basic + data type + transaction + persistence + publish and subscribe + master-slave replication + sentinel + cache penetration, breakdown and avalanche)
JMeter pressure test tool
10g database cannot be started when using large memory host
随机推荐
Core concepts of microservice architecture
大专的我,闭关苦学 56 天,含泪拿下阿里 offer,五轮面试,六个小时灵魂拷问
Android篇:2019初中级Android开发社招面试解答(中
Strange bug of cnpm
Android 面试主题集合整理
JS 力扣刷题 102. 二叉树的层序遍历
AtomicIntegerArray源码分析与感悟
AtCoder Beginner Contest 248C Dice Sum (生成函数)
Choreographer全解析
China creates vast research infrastructure to support ambitious climate goals
Small case of web login (including verification code login)
专题测试05·二重积分【李艳芳全程班】
Test the time required for Oracle library to create an index with 7 million data in a common way
Search ideas and cases of large amount of Oracle redo log
L2-024 部落 (25 分)
神经元与神经网络
Two ways to deal with conflicting data in MySQL and PG Libraries
Android interview theme collection
sys. dbms_ scheduler. create_ Job creates scheduled tasks (more powerful and rich functions)
[code analysis (4)] communication efficient learning of deep networks from decentralized data