当前位置:网站首页>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
边栏推荐
- Automatic differentiation and higher order derivative in deep learning framework
- 共享办公室,提升入驻体验
- 【精品】利用动态代理实现事务统一管理 二
- dataBinding中使用include
- 玩转二叉树 (25 分)
- LINQ学习系列-----1.4 匿名对象
- 求简单类型的矩阵和
- 匿名類型(C# 指南 基礎知識)
- 怎样读取Excel表格到数据库
- Idea is configured to connect to the remote database mysql, or Navicat fails to connect to the remote database (solved)
猜你喜欢
随机推荐
L2-3 浪漫侧影 (25 分)
1099 建立二叉搜索树 (30 分)
OneFlow学习笔记:从Functor到OpExprInterpreter
Use include in databinding
HAL库的RCC简介
After a circle, I sorted out this set of interview questions..
Yangtao electronic STM32 Internet of things entry 30 step notes IV. engineering compilation and download
MATLAB入门资料
怎样读取Excel表格到数据库
K210 learning notes (II) serial communication between k210 and stm32
Test your machine learning pipeline
RPC procedure
Go语言自学系列 | golang结构体作为函数参数
LLVM之父Chris Lattner:编译器的黄金时代
Detailed description of self feeling of auricular point weight loss 0422
MATLAB 画五星红旗
Introduction to protobuf
面了一圈,整理了这套面试题。。
Complete binary search tree (30 points)
请提前布局 Star Trek突破链游全新玩法,市场热度持续高涨









