当前位置:网站首页>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
边栏推荐
猜你喜欢
Use of Arthas in JVM tools
OneFlow学习笔记:从Functor到OpExprInterpreter
flask项目跨域拦截处理以及dbm数据库学习【包头文创网站开发】
增强现实技术是什么?能用在哪些地方?
IDEA导入commons-logging-1.2.jar包
Notes on 30 steps of introduction to the Internet of things of yangtao electronics STM32 III. cubemx graphical programming and setting the IO port on the development board
OneFlow學習筆記:從Functor到OpExprInterpreter
洋桃电子STM32物联网入门30步笔记三、新建CubeIDE工程和设置讲解
DJ音乐管理软件Pioneer DJ rekordbox
Consensus Token:web3.0生态流量的超级入口
随机推荐
STM32使用HAL库,整体结构和函数原理介绍
On time atom joins hands with oneos live broadcast, and the oneos system tutorial is fully launched
Word plus watermark
Basic usage of synchronized locks
Yangtao electronic STM32 Internet of things introduction 30 steps notes 1. The difference between Hal library and standard library
Excle plus watermark
mycat配置
okcc呼叫中心外呼系统智能系统需要用多大的盘存录音?
Detailed description of self feeling of auricular point weight loss 0422
LeetCode396.旋转数组
【IndexOf】【lastIndexOf】【split】【substring】用法详解
LINQ学习系列-----1.4 匿名对象
LaTeX数学公式
Protobuf简介
L2-3 浪漫侧影 (25 分)
STM32F103ZET6【标准库函数开发】----库函数介绍
Kubernetes如何使用harbor拉去私有镜像
HAL库的RCC简介
Type anonyme (Principes fondamentaux du Guide c)
四张图弄懂matplotlib的一些基本用法