Can I Post the lette
来源:互联网 发布:zbrush mac 破解教程 编辑:程序博客网 时间:2024/05/17 03:32
深搜dfs或广搜bfs都可以.
I am a traveler. I want to post a letter to Merlin. But because there are so many roads I can walk through, and maybe I can’t go to Merlin’s house following these roads, I must judge whether I can post the letter to Merlin before starting my travel.
Suppose the cities are numbered from 0 to N-1, I am at city 0, and Merlin is at city N-1. And there are M roads I can walk through, each of which connects two cities. Please note that each road is direct, i.e. a road from A to B does not indicate a road from B to A.
Please help me to find out whether I could go to Merlin’s house or not.
There are multiple input cases. For one case, first are two lines of two integers N and M, (N<=200, M<=N*N/2), that means the number of citys and the number of roads. And Merlin stands at city N-1. After that, there are M lines. Each line contains two integers i and j, what means that there is a road from city i to city j.
The input is terminated by N=0.
#include <stack>#include <iostream>#include <memory.h>#include <string>#include <vector>using namespace std; bool visited[202];int main() { int n,m; while(cin >> n && n != 0) { cin >> m; int x,y; vector<int> g[200]; for(int i = 0;i < m;i++) { cin >> x >> y; g[x].push_back(y); } memset(visited,false,sizeof(visited)); stack<int> s; s.push(0); visited[0] = true; while(!s.empty()) { int v = s.top(); s.pop(); for(int i = 0;i < g[v].size();i++) { if(!visited[g[v][i]]) { visited[g[v][i]] = true; s.push(g[v][i]); //break; } } } if(visited[n - 1]) cout << "I can post the letter" << endl; else cout << "I can't post the letter" << endl; } return 0; }
- Can I Post the lette
- Sicily 1155. Can I Post the lette
- 1155. Can I Post the lette
- sicily1155. Can I Post the lette
- sicily 1155. Can I Post the lette
- 1155. Can I Post the lette
- Sicily 1155. Can I Post the lette
- 1155. Can I Post the lette
- sicily 1155. Can I Post the lette
- 算法学习【12】—— 1155. Can I Post the lette
- [sicily online]1155. Can I Post the lette(图的深度优先搜索)
- 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
- <OJ_Sicily>Can I Post the letter
- Sicily 1155. Can I Post the letter
- 1155. Can I Post the letter(有向图遍历判断两点是否可到达)
- JAVA中的串口通信
- android 应用基础(Activities)
- Android中自定义View和自定义动画
- 最小双基回文数
- Centos VPN搭建一件安装脚本
- Can I Post the lette
- CSS选择器种类及介绍
- 在vs中线程死锁时的一些调试经验
- onInterceptTouchEvent和onTouchEvent调用时序
- JS中JSON解析
- 一些简单的编程练习题
- targetSdkVersion
- 给各位大神的一封问信
- Jsoup网页内容抓取分析