2019 CSP-J-work

2019 CSP-J-work

/*
At first,I connect edges like  x and x+n.
Then,I count the shortest path to '1'.
Finally,I judge y%2 and the shortest path.
That's all of my programme.
*/
/*Warning in shortest path:"Depth-First-Search"is not a suitable method for this problem,
                           because we don't make sure the depth,
                           and "Breadth-First-Search" is suitable
						   because we know the Breadth.
*/
#include<bits/stdc++.h>
using namespace std;
const int maxnt=(2*(1e5)+10);
int n,m,q,dis[maxnt];
vector<int> E[maxnt];
void connect(int x,int y)
{
	E[x].push_back(y);
	E[y].push_back(x);
}
//void dfs(int x)
//{
//	for(int i=0;i<E[x].size();i++)
//	{
//		int to=E[x][i];
//		if(dis[to]!=-1&&dis[to]<=dis[x]+1)
//			continue;
//		dis[to]=dis[x]+1;
//		dfs(to);
//	}
//}
int main()
{
//	freopen("work.in","r",stdin);
//	freopen("work.out","w",stdout);
	cin>>n>>m>>q;
	for(int i=1;i<=m;i++)
	{
		int u,v;
		cin>>u>>v;
		connect(u,v+n);
		connect(v,u+n);
	}
	memset(dis,-1,sizeof(dis));
	dis[1]=0;
//	dfs(1);
	queue<int> qu;
	qu.push(1);
	while(!qu.empty())
	{
		int t=qu.front();
		qu.pop();
		for(int i=0;i<E[t].size();i++)
		{
			int to=E[t][i];
			if(dis[to]!=-1)
				continue;
			dis[to]=dis[t]+1;
			qu.push(to);
		}
	}
	for(int i=1;i<=q;i++)
	{
		int x,y;
		cin>>x>>y;
		bool ans;
		if(y&1) ans=dis[x+n]!=-1&&dis[x+n]<=y;
		else    ans=dis[x]!=-1&&dis[x]<=y;
		puts(ans?"Yes":"No");
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值