[DFS] F-Call to your teacher

题目地址:https://www.nowcoder.com/acm/contest/76/F

搜索

利用队列有序性质直接往后搜索即可 

搜过的直接删除 

通俗易懂

#include <iostream>
#include <queue>
using namespace std;
int main() 
{
	queue <int> q1[200];
	int n,m,x,y;
	cin>>n>>m;
	while(m--) 
	{
		cin>>x>>y;
		q1[x].push(y);    //建立队列
	}
	int pos=1;
	while(!(q1[pos].empty())) //搜索
	{
		int tmp=pos;
		pos=q1[pos].front();
		q1[tmp].pop();
		if(pos==n) 
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}
原文地址:https://www.cnblogs.com/zeolim/p/12270782.html