首页 > 其他分享 >P1196 [NOI2002] 银河英雄传说

P1196 [NOI2002] 银河英雄传说

时间:2023-03-14 18:13:28浏览次数:44  
标签:sz fx int fy fa 银河 NOI2002 find P1196

有一个30000*N(i) 的列队,2种操作

1. M i,j    i行移动到j行的末尾

2.C i,j   询问i行和j行的距离(如果在同一列)

 

#include <bits/stdc++.h>
using namespace std ;
 const int N=3e4;
 int fa[N+2],L[N],n,sz[N]; 
 
 int find(int x){
 	if(x==fa[x]) return x;
 	int t=find(fa[x]);
 	L[x]+=L[fa[x]];
 	
 	return fa[x]=t;
 }
 
 signed main(){
 	int x,y,tes;char op;
 	cin>>tes;
 	for(int i=1;i<=N;i++) fa[i]=i,sz[i]=1;
 	while(tes--){
 		cin>>op>>x>>y; int fx=find(x),fy=find(y);
 		
 		if(op=='M') 
 			L[fx]+=sz[fy],fa[fx]=fa[fy],sz[fy]+=sz[fx],sz[fx]=0;
 		else{
 			if(fx==fy) cout<<abs(L[x]-L[y])-1<<endl;
 			else cout<<-1<<endl;
 		}
 	}
 }
 
 
 

 

标签:sz,fx,int,fy,fa,银河,NOI2002,find,P1196
From: https://www.cnblogs.com/towboa/p/17215825.html

相关文章

  • 银河麒麟KylinV10安装openoffice4.1.14
    使用步骤1.下载openoffice建议去官网下载,这里给出官网地址:https://www.openoffice.org/download/2.安装openoffice2.1、在cd/usr/local目录下创建openoffce文件夹......
  • 银河麒麟服务器V10 SP3 安装ZooKeeper
    服务器zookeeper安装一、软件介绍ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件。它是一个为分布......
  • 银河麒麟安装GeoServer服务
    基于银河麒麟V10SP3下安装部署GeoServer地图服务一、环境 Java1.8.0_361Geoserver2.17.2GeoServer2.17.2下载:https://nchc.dl.sourceforge.net/project/geoserve......
  • 银河麒麟kylin_v10安装OpenLiteSpeed
    系统版本:kylinv10sp2更新yum源[root@localhost~]#wget-O/etc/yum.repos.d/CentOS-Base.repohttps://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.reposed-......
  • 银河麒麟v10 sp1 安装 PostgreSQL 11.16
    一、安装环境   操作系统:银河麒麟v10 sp3 x86_64   内核版本:   PostgreSQL版本:11.16二、安装过程2.1下载源码包创建目录mkdir-p/tools/postgresql......
  • 银河麒麟V10——Postgres-12.5主从编译安装
    一、机器信息IP/主机名备注192.168.50.1/Rz01.local 主库192.168.50.2/Rz02.local 从库 二、编译包下载链接:https://pan.baidu.com/s/1fiOmYB8uplfA1LQDy_LhqQ提取......
  • 在 银河麒麟操作系统 v10 中离线安装 docker 环境
    详情请参考以下链接:https://blog.csdn.net/qq_30665009/article/details/125938033https://little-star.love/posts/6da98871简略版本:#查看系统版本cat/etc/os-rel......
  • 银河麒麟V10系统的 postgresql/postgis完整部署
    一、posgresql部署1、安装前可以先进行用户以及用户组的配置,方便后面进行授权(通过编译安装也需要,后续步骤会体现)。用户配置#新增用户组groupaddpostgres#创建用户......
  • 银河麒麟V10系统安装Redis
    1、[root@localhostopt]#yuminstallcpp输入:y  2、[root@localhostopt]#yuminstallbinutils  3、[root@localhostopt]#yuminstallglibc4、[root@......
  • 银河麒麟系统安装mysql数据库
    1.1 准备材料mysql-5.7.28-linux-glibc2.12-x86_64.tar.gzMySQL5.7下载地址https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz......