sicily:1155.Can I Post the letter
来源:互联网 发布:python安装pip命令 编辑:程序博客网 时间:2024/05/25 19:58
深度优先搜索的核心是确定下一层节点的选择。
<span style="font-size:14px;">#include <iostream>#include <queue>using namespace std;const int MAX_SIZE = 201;int map[MAX_SIZE][MAX_SIZE];bool visited[MAX_SIZE];int n, m;bool ans;void init() {ans = false;for (int i = 0; i < n; i++) {for (int j = 0; j < n; j++)map[i][j] = -1;map[i][i] = 0;visited[i] = false;}}void bfs(int s) {visited[s] = true;queue<int> q;q.push(s);while (!q.empty()) {int u = q.front();for (int i = 0; i < n; i++) {if (map[u][i] > 0 && !visited[i]) {if (i == n - 1) {ans = true;break;}visited[i] = true;q.push(i);}}q.pop();}}int main() {while (cin >> n && n) {init();cin >> m;int u, v;for (int i = 0; i < m; i++) {cin >> u >> v;map[u][v] = 1;}bfs(0);if (ans) cout << "I can post the letter\n";else cout << "I can't post the letter\n";}return 0;}</span>
0 0
- sicily:1155.Can I Post the letter
- Sicily 1155. Can I Post the letter
- sicily 1155 Can I Post the letter
- Sicily 1155 Can I Post the letter
- sicily 1155 Can i post the letter
- Sicily 1155. Can I Post the lette
- sicily 1155. Can I Post the lette
- Sicily 1155. Can I Post the lette
- sicily 1155. Can I Post the lette
- <OJ_Sicily>Can I Post the letter
- 1155. Can I Post the letter(有向图遍历判断两点是否可到达)
- [sicily online]1155. Can I Post the lette(图的深度优先搜索)
- 1155. Can I Post the lette
- 1155. Can I Post the lette
- 1155. Can I Post the lette
- Can I Post the lette
- sicily1155. Can I Post the lette
- 算法学习【12】—— 1155. Can I Post the lette
- bzoj3533 凸包+线段树+三分
- Android自定义控件2
- 视频真实地址解析分析
- 修改Launcher3应用Icon的样式
- oc中传统的get和set方法
- sicily:1155.Can I Post the letter
- RecycleView使用体验(二)
- win7 64位环境安装插件pycrypto-2.6.1报错:Unable to find vcvarsall.bat
- 242 Valid Anagram
- 在启动tomcat服务器时候加载一个action的方法
- ubuntu---mysql操作数据表
- hadoop 各类key value分隔符参数
- 2015.12.31
- 安装jdk一次失败发现的问题