最后 4 个点 RE 了,求助。
图上DP+SPFA's cede:
#include<bits/stdc++.h>
//#define int long long
#define N 2015
#define INF 1e9+9
using namespace std;
typedef struct Edge{
int to,next;
}Edge;
int n,m,q;
int cnt,head[N];
Edge edge[N<<1];
int dis[N][2];
queue<int> que;
inline void SPFA(){
memset(dis,INF,sizeof(dis));
int start=1;
dis[start][0]=0;
que.push(start);
while(que.size()){
int loc=que.front();
que.pop();
int k=head[loc];
while(k!=0){
bool inQue=false;
int v=edge[k].to;
if(dis[v][0]>dis[loc][1]+1){
dis[v][0]=dis[loc][1]+1;
que.push(v);
inQue=true;
}
if(dis[v][1]>dis[loc][0]+1){
dis[v][1]=dis[loc][0]+1;
if(!inQue)que.push(v);
}
k=edge[k].next;
}
}
}
inline void addEdge(int u,int v){
edge[++cnt].to=v;
edge[cnt].next=head[u];
head[u]=cnt;
}
inline void read(int &num){
int x=0,f=1;
char ch=getchar();
while(ch>'9'||ch<'0'){
f=(ch=='-')?-1:1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=(x<<3)+(x<<1)+(ch^48);
ch=getchar();
}
num=x*f;
}
signed main(){
read(n);
read(m);
read(q);
for(int i=1;i<=m;++i){
int u,v;
read(u);
read(v);
addEdge(u,v);
addEdge(v,u);
}
SPFA();
while(q--){
int a,l;
read(a);
read(l);
if(l&1){
puts(dis[a][1]<=l?"Yes":"No");
}else{
puts(dis[a][0]<=l?"Yes":"No");
}
}
}