当前位置:网站首页>L2-024 tribe (25 points) (and check the collection)
L2-024 tribe (25 points) (and check the collection)
2022-04-23 08:44:00 【.Ashy.】
describe :
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 .
Input format :

Output :
First, output the total number of people in this community in one line 、 And the number of tribes that don't intersect each other . Then for each query , If they belong to the same tribe , Output in one line Y, Otherwise output N.
sample input :
4
3 10 1 2
2 3 4
4 1 5 7 8
3 9 6 4
2
10 5
3 7
sample output :
10 2
Y
N
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const ll maxx = 1e18;
const int N = 1e6+100;
const int p = 1e4+10;
const double eps = 1e-8;
int n,m,t,k;
int a,bs;
int b[p];
int pre[N],max1,cnt;
map<int,int>mp;
int find(int x)
{
if(x==pre[x]) return x;
else return pre[x]=find(pre[x]);
}
void unionn(int x,int y)
{
int ya=find(x);
int yb=find(y);
pre[ya]=yb;
}
int main()
{
cin>>n;
for(int i=1;i<=1e6;i++)
{
pre[i]=i;
}// Processing the root node
for(int i=1;i<=n;i++)
{
cin>>k;
for(int j=1;j<=k;j++)
{
cin>>b[j];
max1=max(max1,b[j]);
}// Input , Find out the total number of people
for(int j=1;j<=k;j++)
{
for(int s=j+1;s<=k;s++)
{
unionn(b[j],b[s]);
}
}// and
}
cin>>m;
for(int i=1;i<=max1;i++)
{
if(mp[find(i)]==0)
{
mp[find(i)]=1;
cnt++;
}// Number of intersecting sets not found
}
cout<<max1<<" "<<cnt<<endl;
for(int i=1;i<=m;i++)
{
cin>>a>>bs;
if(find(a)==find(bs))
cout<<"Y"<<endl;
else
cout<<"N"<<endl;
}// check
return 0;
}
版权声明
本文为[.Ashy.]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230842481712.html
边栏推荐
猜你喜欢
随机推荐
洋桃电子STM32物联网入门30步笔记二、CubeIDE下载、安装、汉化、设置
Output first order traversal according to second order and middle order traversal (25 points)
Reference passing 1
Illegal character in scheme name at index 0:
洋桃电子STM32物联网入门30步笔记三、新建CubeIDE工程和设置讲解
LeetCode396.旋转数组
洋桃电子STM32物联网入门30步笔记三、CubeMX图形化编程、设置开发板上的IO口
rembg 分割mask
GUI编程简介 swing
cadence的工艺角仿真、蒙特卡洛仿真、PSRR
RPC procedure
Complete binary search tree (30 points)
'恶霸' Oracle 又放大招,各大企业连夜删除 JDK。。。
ONEFLOW learning notes: from functor to opexprinter
swagger文档导出自定义v2/api-docs拦截
第一性原理 思维导图
经典题目刷一刷
汇编语言与逆向工程 栈溢出漏洞逆向分析实验报告
让地球少些“碳”息 度能在路上
Large amount of data submitted by form post









