家族解题
来源:互联网 发布:设计淘宝店铺标志图片 编辑:程序博客网 时间:2024/06/10 06:27
题目地址:http://codevs.cn/problem/1073/
题目描述 Description
若某个家族人员过于庞大,要判断两个是否是亲戚,确实还很不容易,现在给出某个亲戚关系图,求任意给出的两个人是否具有亲戚关系。 规定:x和y是亲戚,y和z是亲戚,那么x和z也是亲戚。如果x,y是亲戚,那么x的亲戚都是y的亲戚,y的亲戚也都是x的亲戚。
输入描述 Input Description
第一行:三个整数n,m,p,(n<=5000,m<=5000,p<=5000),分别表示有n个人,m个亲戚关系,询问p对亲戚关系。 以下m行:每行两个数Mi,Mj,1<=Mi,Mj<=N,表示Ai和Bi具有亲戚关系。 接下来p行:每行两个数Pi,Pj,询问Pi和Pj是否具有亲戚关系。
输出描述 Output Description
P行,每行一个’Yes’或’No’。表示第i个询问的答案为“具有”或“不具有”亲戚关系。
样例输入 Sample Input
6 5 3
1 2
1 5
3 4
5 2
1 3
1 4
2 3
5 6
样例输出 Sample Output
Yes
Yes
No
数据范围及提示 Data Size & Hint
n<=5000,m<=5000,p<=5000
#include<stdio.h>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
int a[9999];
int n, m, p;
int x, y;
cin >> n >> m >> p;
int b[9999];
for (int i = 1; i <=n; i++)
{
a[i] = i;
}
for (int i = 0; i <m ; i++)
{
cin >> x >> y;
if (a[x]>a[y])
{
int t = a[x];
for (int j = 1; j <= n; j++)
{
if (a[j] == t)
{
a[j] = a[y];
}
}
}
else
{
int t = a[y];
for (int j = 1; j <= n; j++)
{
if (a[j] ==t)
{
a[j] = a[x];
}
}
}
}
for (int i = 0; i < p; i++)
{
cin >> x >> y;
if (a[x]==a[y])
{
b[i] = 1;
}
else
{
b[i] = 0;
}
}
for (int i = 0; i < p; i++)
{
if (b[i])
{
cout << "Yes" << endl;
}
else
{
cout << "No" << endl;
}
}
return 0;
}
虎逼,SCDN昨天发的 说需要审核今天一来看毛都没有
0 0
- 家族解题
- P1034家族解题报告
- 1073 家族【解题报告】
- 家族
- 家族
- 家族
- 家族
- 家族
- 家族
- 家族
- codevs 1073 家族 并查集 解题报告
- VA家族
- SQL家族
- Watir 家族
- UNIX家族
- Watir 家族
- 施耐德家族
- 802.11 家族
- Android--数据库操作辅助类:SQLiteOpenHelper
- 服务器和客户端同步状态,客户端不能依赖服务器的响应
- hdu 2594 Simpsons’ Hidden Talents (kmp扩展)
- 对C++继承的一点理解
- Java观察者模式 : Observer / Observable
- 家族解题
- 学习了一段时间WEB前端开发,谈一谈个人理解
- 工具[Source Insight]_Source Insight基本使用(1)
- SRM 649 div2 500(dp)
- Android Drawable 转化成 Bitmap
- 居然没拿到offer,失落
- 替换ExpandableListView右边箭头Group Indicator(小图标)
- URAL 1009
- MongoDB中的主从事务