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;
}