知道过不了为什么一分没有(样例过了)
查看原帖
知道过不了为什么一分没有(样例过了)
735141
hiGh_sPeEd楼主2023/10/4 11:38
#include <iostream>
#include <queue>
#define ll long long
using namespace std;
ll n,m,q,asd[1001][1001],temp1,temp2;
queue<ll>niko;
int main(){
	cin>>n>>m>>q;
	for(ll i=1;i<=m;i++){
		cin>>temp1>>temp2;
		asd[temp1][temp2]=1;
		asd[temp2][temp1]=1;
	}
	temp1=0;
	temp2=0;
	for(ll i=1;i<=q;i++){
		cin>>temp1>>temp2;
		if(temp1==1&&temp2==1)cout<<"NO"<<endl;
		else if(temp2==1){
			if(asd[1][temp1]!=1)cout<<"NO"<<endl;
			else cout<<"YES"<<endl;
		}else{
			niko.push(temp1);
			while(temp2>0){
				ll zztemp,cdtemp;
				cdtemp=niko.size();
				for(ll i=0;i<cdtemp;i++){
					zztemp=niko.front();
					for(ll j=1;j<=n;j++){
						if(asd[zztemp][j]==1){
							niko.push(j);
						}
					}
					niko.pop();
				} 
				temp2--;
			}
			bool flag=0;
			while(!niko.empty()){
				ll zztemp=niko.front();
				if(zztemp==1&&flag==0){
					cout<<"YES"<<endl;
					flag=1;
				}
				niko.pop();
			}
			if(!flag)cout<<"NO"<<endl;
		}
	}
	return 0;
}
2023/10/4 11:38
加载中...