文章标题
2016-06-21 13:23
232 查看
#include<stdio.h> #include<string.h> struct node { int x,y; int ans; }q[1001]; int map[1001][1001]; int book[1001]; int m,n; void bfs( int x) { int head = 0,tail = 0,i; struct node t,f; t.x=x; t.ans = 0; q[tail++]=t; book[t.x] = 1; while(head < tail) { t = q[head++]; if(t.x == 1) { printf("%d\n",t.ans); return; } for( i =1; i <= n; i++) { f.x = i; if(!book[f.x]&&map[t.x][f.x]==1) { f.ans=t.ans+1; q[tail++] = f; book[f.x]=1; } } } printf("NO\n"); return; } int main() { int a,b; while(~scanf("%d%d",&n,&m)) { memset(map,0,sizeof(map)); memset(book,0,sizeof(book)); while(m--) { scanf("%d%d",&a,&b); map[a][b]=1; } bfs(n); } }
啦啦啦啦
相关文章推荐
- 第16周项目——文件阅读9
- Windows Server 2012 虚拟化实战:域
- C++11 仿函数
- 策略模式 详解
- mysql 查询今天、昨天、上月、本月的数据
- 【原创】项目管理论坛收获分享
- jsp中的input
- Swift - 使用UIDatePicker实现倒计时功能
- IIS发布——HTTP Error 503. The service is unavailable. 应用程序池的程序自动停止
- nginx学习记录--安装和转发到tomcat
- 安卓屏幕适配
- 无法定位程序输入点 inet_ntop 于动态链接库 WS2_32.dll上
- docker 私有仓库查询
- MQTT 物联网连接协议
- 例解 autoconf 和 automake 生成 Makefile 文件
- numpy.array 操作简单总结
- 随便写写不一定对 - 小问题总结
- PHP分页显示和查询
- 我与吴建民先生的一点交集
- docker 私有仓库查询