toj 2190 Nuanran's Idol


2190.   Nuanran's Idol
Time Limit: 3.0 Seconds    Memory Limit: 65536K
Total Runs: 1511    Accepted Runs: 687    Multiple test files



When in his junior middle school, nuanran had been a fan of the famous singer Chen Huilin. She is from Hong Kong, and her English name is Kelly. One of Kelly's best friends is Lin Yilian (another famous singer). Therefore, Lin Yilian is also nuanran's idol. Here, we assume that if A, B are friends and B, C are friends, then A, C are also friends. Nevertheless, all Kelly's friends are nuanran's idols. Because Kelly may have other friends and her friends can also have friends, nuanran have so many idols that he can't know whether a given singer is his idol or not. Can you help him?

Input

Input will consist of multiple test cases, with each test case including the following three parts.

1) A line contains three integers N (the number of singers), M (the number of relations), K (the number of inquiries). 1 ≤ N, M, K ≤ 100000.

2) M lines follow. Each line contains two integers x and y (1 ≤ x, y ≤ N), denoting that x and y are friends. And Kelly is always represented by 1.

3) K lines follow. Each line contains a single integer p (1 ≤ p ≤ N), representing an inquiry.

Input will terminate by the end of file(EOF).

Output

For each inquiry p, you should output "Yes" if p is an idol of nuanran. Otherwise, you should output "No".

Sample Input

10 9 4
1 2
3 4
5 6
5 7
9 10
3 6
4 9
5 9
1 5
10
9
8
3

Sample Output

Yes
Yes
No
Yes


#include<iostream>
#include<cstdio>
using namespace std;

int fa[100003];

int find(int x)
{
	while(fa[x] != x)
	{
		x = fa[x];
	}
	return x;
}

void merge(int x,int y)
{
	int f1 = find(x);
	int f2 = find(y);
	if(f1 < f2) fa[f2] = f1;
	else if(f1 > f2) fa[f1] = f2;
}


int main()
{
	int ns,nr,k,a,b,q;
	while(~scanf("%d%d%d",&ns,&nr,&k))
	{
		//初始化 
		for(int i = 1; i <= ns; i++)
		{
			fa[i] = i;
		}
		
		for(int i = 0; i < nr; i++)
		{
			scanf("%d%d",&a,&b);
			merge(a,b);
		}
		
		for(int i = 0; i < k; i++)
		{
			scanf("%d",&q);
			if(find(q) == 1) printf("Yes\n");
			else printf("No\n");
		}
	}
	return 0;
}
			

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值