当前位置:网站首页>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
边栏推荐
- JVM工具之Arthas使用
- 计算神经网络推理时间的正确方法
- Virtual online exhibition - Online VR exhibition hall realizes 24h immersive exhibition viewing
- Let the earth have less "carbon" and rest on the road
- Get the absolute path of the class according to the bytecode
- 玩转二叉树 (25 分)
- 怎样读取Excel表格到数据库
- Stm32f103zet6 [development of standard library functions] - Introduction to library functions
- 【IndexOf】【lastIndexOf】【split】【substring】用法详解
- okcc呼叫中心外呼系统智能系统需要用多大的盘存录音?
猜你喜欢
bashdb下载安装
RCC introduction of Hal Library
idea底栏打开services
Yangtao electronic STM32 Internet of things entry 30 step notes II. Cube ide download, installation, sinicization and setting
《深度学习》学习笔记(八)
Notes d'apprentissage oneflow: de functor à opexprinterpreter
IDEA导入commons-logging-1.2.jar包
Study notes of deep learning (8)
MATLAB入门资料
Redis Desktop Manager for Mac(Redis可视化工具)
随机推荐
匿名类型(C# 指南 基础知识)
rembg 分割mask
企业微信应用授权/静默登录
STM32F103ZET6【标准库函数开发】----库函数介绍
Queue (C language / linked list)
Latex mathematical formula
基于点云凸包的凹包获取方法
How much inventory recording does the intelligent system of external call system of okcc call center need?
根据字节码获取类的绝对路径
ESP32程序下载失败,提示超时
Idea import commons-logging-1.2 Jar package
Test your machine learning pipeline
SYS_ CONNECT_ BY_ Path (column, 'char') combined with start with connect by prior
Navicat远程连接mysql
MATLAB入门资料
RPC过程
Protobuf简介
《深度学习》学习笔记(八)
L2-024 部落 (25 分)(并查集)
Latex paper typesetting operation