NCD 2019 H. Mr. Hamra and his quantum particles

题意:给你n个数,有m次操作,每次使得两个数相连接,询问q次,问某两个数是否连接在一起.
题解:这其实是一道并查集的裸题,这里就不再多说了,写个路径压缩的find函数即可.
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
using namespace std;
typedef pair<int,int> PII;
typedef pair<long,long> PLL; int t;
int u,v,x,y;
int n,m,q;
int p[N];
int find(int x){ //dsu
if(p[x]!=x) p[x]=find(p[x]);
return p[x];
} int main() {
ios::sync_with_stdio(false);
cin>>t;
while(t--){
cin>>n>>m>>q;
for(int i=1;i<=n;++i) p[i]=i;
while(m--){
cin>>u>>v;
p[find(u)]=find(v);
}
while(q--){
cin>>x>>y;
if(find(x)==find(y)) printf("1");
else printf("0");
}
puts("");
}
return 0;
}
NCD 2019 H. Mr. Hamra and his quantum particles的更多相关文章
- H - Mr. Panda and Birthday Song Gym - 101775H (动态规划)
Mrs. Panda’s birthday is coming. Mr. Panda wants to compose a song as gift for her birthday. It is k ...
- The Preliminary Contest for ICPC Asia Shenyang 2019 H
H. Texas hold'em Poker 思路:根据每个牌型分等级,然后排序按照等级优先,最大值次之,次大值,最后比较剩下值的和. #include<bits/stdc++.h> us ...
- The Preliminary Contest for ICPC Asia Shenyang 2019 H. Texas hold'em Poker
题目链接:https://nanti.jisuanke.com/t/41408 题目意思很简单,就是个模拟过程. #include <iostream> #include <cstr ...
- The Preliminary Contest for ICPC Asia Nanjing 2019 H. Holy Grail
题目链接:https://nanti.jisuanke.com/t/41305 题目说的很明白...只需要反向跑spfa然后输入-dis,然后添-dis的一条边就好了... #include < ...
- NCD 2019 M. NCD Salary
题意 :给你两个指数类型的数\(A^m\)和\(B^n\),比较他们的大小.保证底数和指数中最多只有一个为0. 题解 :题目数据非常大,肯定不能直接比较.由换底公式和\(Log\)函数的性质我们知道: ...
- NCD 2019 C. Hasan and his lazy students
题意:给你一组数,求最长的严格上升子序列及个数(mod 1e9+7) 题解:用动态规划来求LIS,记\(dp[i]\)是数组中第i个位置上的数的LIS最优解,我们遍历一遍原数组,然后找i位置前的LIS ...
- 终端复用工具-tmux
目录 终端复用工具--Tmux 一.为什么要用Tmux? 二.tmux是什么? 三.Tmux基本概念 四.Tmux使用规则 1.安装Tmux 2.基本使用 3.自定义配置文件 五.补充 1.tmux ...
- 集合-Collection接口
集合 和 数组 的比较: 数组 - 本质上就是在内存空间中申请的一段连续内存空间,存放多个相同类型的数据 - 数组一旦定义完毕,则在内存空间中的长度固定. - 插入/删除元素时可能导致大量元素的移动, ...
- [转] Loren on the Art of MATLAB
http://blogs.mathworks.com/loren/2007/03/01/creating-sparse-finite-element-matrices-in-matlab/ Loren ...
随机推荐
- pip不是内部或外部命令解决方法
问题 已经配置好Python环境,但是安装依赖时,出现pip不是内部或外部命令. 解决方法 找到pip.exe文件所在的目录,将所在路径配置到环境变量path中. 再次输入pip
- 【二分搜索树】1、二分查找法的实现 - Binary Search
简单记录 - bobo老师的玩转算法系列–玩转算法 - 二分搜索树 二叉搜索树 Binary Search Tree 查找问题 Searching Problem 查找问题是计算机中非常重要的基础问题 ...
- 最新详解android自动化无障碍服务accessibilityservice以及高版本问题_1_如何开启获得无障碍
前言 无障碍服务accessibilityservice是什么 简单来说 无障碍服务就是一个为残障人士 尤其是视觉障碍人士提供的一个帮助服务.具体就是可以识别控件 文字 可以配合语音助手 操作和 使用 ...
- Lnux:实验 Linux C 编程
实验题目: 实验 3 Linux C 编程 实验目的和要求: 熟悉 Linux 操作系统环境 在 Linux 下编写.执行简单的 C 程序 用 C 语言写自己的 Linux 命令 实验过程: 认真 ...
- Java运算符及包机制
Java中的运算符及包机制 算术运算符:+ - * / % ++ -- 赋值运算符:=,+=,-=,*=,/= 关系运算符:>,<,>=,<=,==,!=,instanceof ...
- 在原生开发中控制HTML5视频!
在原生开发中控制HTML5视频! PC端 视频如何自动播放! 在video标签中添加 autoplay + muted(静音属性!) 温馨提醒: video是一个块级元素! 但是唯一的缺陷就是视频没有 ...
- Understanding go.sum and go.mod file in Go
https://golangbyexample.com/go-mod-sum-module/ Understanding go.sum and go.mod file in Go (Golang) – ...
- nginx http模块开发入门
导语 本文对nginx http模块开发需要掌握的一些关键点进行了提炼,同时以开发一个简单的日志模块进行讲解,让nginx的初学者也能看完之后做到心里有谱.本文只是一个用作入门的概述. 目录 背景 主 ...
- Python学习【第6篇】:集合的定义和基本方法
1.概念 (1)不同元素组成 例: s = {1,2,3,4,4,4,4,4,4}print(s)运行结果:{1, 2, 3, 4}因为是不同元素组成,因此去重了 (2)无序 例: s = {&quo ...
- loj10002喷水装置
长L米,宽W米的草坪里装有N 个浇灌喷头.每个喷头都装在草坪中心线上(离两边各 W/2米).我们知道每个喷头的位置(离草坪中心线左端的距离),以及它能覆盖到的浇灌范围. 请问:如果要同时浇灌整块草坪 ...