【CSU - 1004】Xi and Bo(并查集,裸题)

题干:

Bo has been in Changsha for four years. However he spends most of his time staying his small dormitory. One day he decides to get out of the dormitory and see the beautiful city. So he asks to Xi to know whether he can get to another bus station from a bus station. Xi is not a good man because he doesn't tell Bo directly. He tells to Bo about some buses' routes. Now Bo turns to you and he hopes you to tell him whether he can get to another bus station from a bus station directly according to the Xi's information.

Input

The first line of the input contains a single integer T (0<T<30) which is the number of test cases. For each test case, the first contains two different numbers representing the starting station and the ending station that Bo asks. The second line is the number n (0<n<=50) of buses' routes which Xi tells. For each of the following n lines, the first number m (2<=m<= 100) which stands for the number of bus station in the bus' route. The remaining m numbers represents the m bus station. All of the bus stations are represented by a number, which is between 0 and 100.So you can think that there are only 100 bus stations in Changsha.

Output

For each test case, output the "Yes" if Bo can get to the ending station from the starting station by taking some of buses which Xi tells. Otherwise output "No". One line per each case. Quotes should not be included.

Sample Input

3
0 3
3
3 1 2 3
3 4 5 6
3 1 5 6
0 4
2
3 0 2 3
2 2 4
3 2
1
4 2 1 0 3

Sample Output

No
Yes
Yes

解题报告:

   直接并查集就好了。留给学弟做练习用。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define F first
#define S second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
int f[MAX],q[MAX];
int getf(int v) {return f[v] == v ? v : f[v] = getf(f[v]);
}
void merge(int u,int v) {int t1 = getf(u);int t2 = getf(v);f[t2] = t1;
}
void init() {for(int i = 0; i<=100; i++) {f[i] = i;}
} 
int main()
{int t,m;cin>>t;while(t--) {int st,ed;scanf("%d%d",&st,&ed);scanf("%d",&m);init();for(int num,i = 1; i<=m; i++) {scanf("%d",&num);for(int j = 1; j<=num; j++) {scanf("%d",q+j);}for(int j = 2; j<=num; j++) {merge(q[j],q[j-1]);}}if(getf(st) == getf(ed)) puts("Yes");else puts("No");}return 0 ;
}
//12:33-12:40

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/440451.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

oracle软件静默安装程序,【oracle】静默安装 oracle 11gr2

【序言】oracle 提供了静默安装方法在不适用图形界面的情况下安装 oracle 软件 ,创建db,配置netca,快速完成oracle 的部署。在以下情形中可以使用静默安装a OUI 的 GUI 界面远程交互比较慢 .b 数据库服务器无法使用图形界面访问.c 批量部署oracle (标准环境统一情况下可以使用o…

【2050 Programming Competition - 2050 一万人码 】非官方部分题解(HDU)

1001 开场白 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 12147 Accepted Submission(s): 3502 Problem Description 来自世界各地的年青人在 https://2050.org.cn 握手团聚&#xff0c; 他们是航空…

oracle数据库建表视频,Oracle数据库的创建表全

CREATE TABLE "库名"."表名" ("FEE_ID" VARCHAR2(10 BYTE) constraint ABS_FEE_ID primary key,--主键&#xff0c;必须要有序列"BANK_GROUP_ID" VARCHAR2(5 BYTE),"ABS_PRODUCT_ID" VARCHAR2(30 BYTE))TABLESPACE "表…

oracle的脚本语言是什么意思,Oracle中的sql脚本语言中的循环语句介绍

--sql脚本语言的循环介绍&#xff1a;--1.goto循环点。declarex number;beginx:0;--变量初始化&#xff1b;<>--设置循环点。x:x1;dbms_output.put_line(x);--循环体if x<9 then --进入循环的条件。goto repeat_loop; --用goto关键字引导进入循环。end i…

【poj题集整理】【存下来并不会看】

主要是整理起来自己用的。网上有多个版本。 初级: 一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. (5)构造法.(poj3295) (6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996) 二.图算…

oracle排名怎么去除空值影响,Oracle排序中null值处理方法讲解

1、缺省处理oracle在order by 时缺省认为null是最大值&#xff0c;所以如果是asc升序则排在最后&#xff0c;desc降序则排在最前2、使用nvl函数nvl函数可以将输入参数为空时转换为一特定值&#xff0c;如nvl(employee_name,’张三’)表示当employee_name为空时则返回’张三’&a…

【ZOJ - 3870】Team Formation(异或,思维)

题干&#xff1a; For an upcoming programming contest, Edward, the headmaster of Marjar University, is forming a two-man team from N students of his university. Edward knows the skill level of each student. He has found that if two students with skill lev…

oracle dump enq hw,经典故障分析 - ASSM引发的索引争用与 enq HW -contentio

作者介绍&#xff1a;孙加鹏 云和恩墨技术顾问六年Oracle技术顾问经验&#xff0c;所服务的行业包括电信运营商、金融业、制造业等。擅长Oracle的故障诊断、高可用架构、升级迁移等。目前主要服务于上海金融类客户。1故障概述2017年07月24日11:58左右&#xff0c;客户核心数据库…

【ZOJ - 3946】Highway Project(最短路子图,维护双权值,贪心,最小树形图)

题干&#xff1a; Edward, the emperor of the Marjar Empire, wants to build some bidirectional highways so that he can reach other cities from the capital as fast as possible. Thus, he proposed the highway project. The Marjar Empire has N cities (including…

oracle 主键约束复制,Oracle主键及约束

Oracle主键Primary Key包含非空约束及唯一约束。添加主键的语句alter table table_nameadd constraint cons_name primary key(col_name);查看主键是否被创建成功select dbms_metadata.get_ddl(‘OBJECT_TYPE‘,‘NAME‘,‘SCHEMA‘) from dual;OBJECT_TYPE (TABLE,PARTITION,I…

【ZOJ - 3956】Course Selection System(01背包)

题干&#xff1a; There are n courses in the course selection system of Marjar University. The i-th course is described by two values: happiness Hi and credit Ci. If a student selects m courses x1, x2, ..., xm, then his comfort level of the semester can be…

oracle 账户 锁定 密码忘记了,Oracle System密码忘记 密码修改、删除账号锁定lock

运行cmd命令行录入 sqlplus /nolog 无用户名登录conn /as sysdba 连接到数据本地数据alter user system identified by password; 修改System 密码 为passwordD:\oracle\ora92\bin>sqlplus /nologSQL*Plus: Release 9.2.0.1.0 - Production on 星期四 8月 16 11:32:22 …

【计蒜客 - 2019南昌邀请赛网络赛 - K】MORE XOR(数学,找规律,打表)

Given a sequence of nn numbers a_1, a_2, \cdots, a_na1​,a2​,⋯,an​ and three functions. Define a function f(l,r)f(l,r) which returns \oplus a[x]⊕a[x] (l \le x \le rl≤x≤r). The \oplus⊕ represents exclusive OR. Define a function g(l,r)g(l,r) which r…

oracle编译失效物化视图,使用“不存在”的Oracle物化视图

启用快速刷新很棘手,有许多奇怪的限制和无用的错误消息.在这种情况下,您需要创建物理化视图日志WITH ROWID,使用()连接语法,并为每个表添加ROWID.create table tablea(my_id number primary key,a number);create table tableb(my_id number primary key,b number);create mate…

【计蒜客 - 2019南昌邀请赛网络赛 - M】Subsequence(字典树,dp预处理)

题干&#xff1a; Give a string SS and NN string T_iTi​ , determine whether T_iTi​ is a subsequence of SS. If ti is subsequence of SS, print YES,else print NO. If there is an array \lbrace K_1, K_2, K_3,\cdots, K_m \rbrace{K1​,K2​,K3​,⋯,Km​} so th…

Linux把文件移动到容器外,Docker容器与主机之间拷贝文件的方法

一般情况下&#xff0c;我们在启动Docker容器的时候可以使用-v参数映射宿主机的文件或者目录到容器里&#xff0c;这样的话&#xff0c;在宿主机相关目录下的文件修改会自动在容器里生效。但是&#xff0c;如果我们已经启动了一个容器的话&#xff0c;就只能使用下面的这种方式…

【计蒜客 - 2019南昌邀请赛网络赛 - H】Coloring Game(找规律,思维dp)

题干&#xff1a; David has a white board with 2 \times N2N grids.He decides to paint some grids black with his brush.He always starts at the top left corner and ends at the bottom right corner, where grids should be black ultimately. Each time he can mov…

linux打包tar包命令,Linux压缩打包方法连载之一:tar命令

Linux压缩打包方法有很多种&#xff0c;以下讲了tar命令的概念&#xff0c;同时文列举了多种范例供大家查看&#xff0c;希望对大家有所帮助....tar命令[rootlinux ~]# tar [-cxtzjvfpPN] 文件与目录 ....参数&#xff1a;-c &#xff1a;建立一个压缩文件的参数指令(create 的…

【计蒜客 - 2019南昌邀请赛网络赛 - I】Max answer(单调栈,RMQ)

题干&#xff1a; Alice has a magic array. She suggests that the value of a interval is equal to the sum of the values in the interval, multiplied by the smallest value in the interval. Now she is planning to find the max value of the intervals in her arr…

linux联想电脑wifi密码,联想笔记本Y7000—ubuntu16.4无法开启wifi的解决办法

一、问题描述本人使用的是联想游戏本Y7000&#xff0c;默认装入Win10系统&#xff0c;然当装入Ubuntu16.04双系统时&#xff0c;会出现无线硬件开关关闭的问题&#xff0c;当然也就无法连网。使用rfkill list all会出现如下提示0:ideapad_wlan: Wireless LANSoft blocked: noHa…