• 题意:给你n个数,有m次操作,每次使得两个数相连接,询问q次,问某两个数是否连接在一起.

  • 题解:这其实是一道并查集的裸题,这里就不再多说了,写个路径压缩的find函数即可.

  • 代码:

    1. #include <iostream>
    2. #include <cstdio>
    3. #include <cstring>
    4. #include <cmath>
    5. #include <algorithm>
    6. #include <stack>
    7. #include <queue>
    8. #include <vector>
    9. #include <map>
    10. #include <set>
    11. #include <unordered_set>
    12. #include <unordered_map>
    13. #define ll long long
    14. #define fi first
    15. #define se second
    16. #define pb push_back
    17. #define me memset
    18. const int N = 1e6 + 10;
    19. const int mod = 1e9 + 7;
    20. using namespace std;
    21. typedef pair<int,int> PII;
    22. typedef pair<long,long> PLL;
    23. int t;
    24. int u,v,x,y;
    25. int n,m,q;
    26. int p[N];
    27. int find(int x){ //dsu
    28. if(p[x]!=x) p[x]=find(p[x]);
    29. return p[x];
    30. }
    31. int main() {
    32. ios::sync_with_stdio(false);
    33. cin>>t;
    34. while(t--){
    35. cin>>n>>m>>q;
    36. for(int i=1;i<=n;++i) p[i]=i;
    37. while(m--){
    38. cin>>u>>v;
    39. p[find(u)]=find(v);
    40. }
    41. while(q--){
    42. cin>>x>>y;
    43. if(find(x)==find(y)) printf("1");
    44. else printf("0");
    45. }
    46. puts("");
    47. }
    48. return 0;
    49. }

NCD 2019 H. Mr. Hamra and his quantum particles的更多相关文章

  1. 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 ...

  2. The Preliminary Contest for ICPC Asia Shenyang 2019 H

    H. Texas hold'em Poker 思路:根据每个牌型分等级,然后排序按照等级优先,最大值次之,次大值,最后比较剩下值的和. #include<bits/stdc++.h> us ...

  3. The Preliminary Contest for ICPC Asia Shenyang 2019 H. Texas hold'em Poker

    题目链接:https://nanti.jisuanke.com/t/41408 题目意思很简单,就是个模拟过程. #include <iostream> #include <cstr ...

  4. The Preliminary Contest for ICPC Asia Nanjing 2019 H. Holy Grail

    题目链接:https://nanti.jisuanke.com/t/41305 题目说的很明白...只需要反向跑spfa然后输入-dis,然后添-dis的一条边就好了... #include < ...

  5. NCD 2019 M. NCD Salary

    题意 :给你两个指数类型的数\(A^m\)和\(B^n\),比较他们的大小.保证底数和指数中最多只有一个为0. 题解 :题目数据非常大,肯定不能直接比较.由换底公式和\(Log\)函数的性质我们知道: ...

  6. NCD 2019 C. Hasan and his lazy students

    题意:给你一组数,求最长的严格上升子序列及个数(mod 1e9+7) 题解:用动态规划来求LIS,记\(dp[i]\)是数组中第i个位置上的数的LIS最优解,我们遍历一遍原数组,然后找i位置前的LIS ...

  7. 终端复用工具-tmux

    目录 终端复用工具--Tmux 一.为什么要用Tmux? 二.tmux是什么? 三.Tmux基本概念 四.Tmux使用规则 1.安装Tmux 2.基本使用 3.自定义配置文件 五.补充 1.tmux ...

  8. 集合-Collection接口

    集合 和 数组 的比较: 数组 - 本质上就是在内存空间中申请的一段连续内存空间,存放多个相同类型的数据 - 数组一旦定义完毕,则在内存空间中的长度固定. - 插入/删除元素时可能导致大量元素的移动, ...

  9. [转] Loren on the Art of MATLAB

    http://blogs.mathworks.com/loren/2007/03/01/creating-sparse-finite-element-matrices-in-matlab/ Loren ...

随机推荐

  1. If you see someone without smile

    If you see someone without smile, give them one of yours. 难怪我每次和不认识的人说话都放肆大笑.

  2. Linux面试必备

    1.Linux的体系结构

  3. kubernets之statefulset资源

    一  了解Statefulset 1.1  对比statefulset与RS以及RC的区别以及相同点 Statefulset是有状态的,而RC以及RS等是没有状态的 Statefulset是有序的,拥 ...

  4. HTML5与CSS3知识点总结

    好好学习,天天向上 本文已收录至我的Github仓库DayDayUP:github.com/RobodLee/DayDayUP,欢迎Star 原文链接:https://blog.csdn.net/we ...

  5. JAVA SSM整合流程以及注意点

    1.搭建整合环境 整合说明:SSM整合可以使用多种方式,咱们会选择XML + 注解的方式 先搭建整合的环境 先把Spring的配置搭建完成 再使用Spring整合SpringMVC框架 最后使用Spr ...

  6. python基础之 列表、元组操作 字符串操作 字典操作 集合操作 文件操作 字符编码与转码

    本节内容 列表.元组操作 字符串操作 字典操作 集合操作 文件操作 字符编码与转码 1. 列表.元组操作 列表是我们最以后最常用的数据类型之一,通过列表可以对数据实现最方便的存储.修改等操作 定义列表 ...

  7. 网络Devops探索与实践 流程管理分析师

    https://mp.weixin.qq.com/s/OKLiDi78uB8ZkPG2kUVxvA 网络Devops探索与实践 王镇 鹅厂网事 2020-09-23  9月16日举办的2020 ODC ...

  8. Jenkins部署web项目到Tomcat(shell脚本)

    一.首先配置Publish Over SSH插件 配置地址:系统管理-->系统设置-->Publish over SSH(需要安装Publish over SSH插件) 二.jenkins ...

  9. Communicating sequential processes CSP 通信顺序进程 CSP writing to a file by name (process, Erlang) vs. writing to a file descriptor (channel, Go)

    the-way-to-go_ZH_CN/01.2.md at master · Unknwon/the-way-to-go_ZH_CN https://github.com/Unknwon/the-w ...

  10. 算法总结篇---AC自动机

    目录 写在前面 算法流程 引例: 概述: Trie树的构建(第一步) 失配指针(第二步) 构建失配指针 字典树和字典图 多模式匹配 例题 写在前面 鸣谢: OiWiki 「笔记」AC 自动机---Lu ...