sicily1155. Can I Post the lette
来源:互联网 发布:直播淘宝小二 编辑:程序博客网 时间:2024/05/19 04:05
1155. Can I Post the lette
Constraints
Time Limit: 1 secs, Memory Limit: 32 MB
Description
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.
Input
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.
Output
For each test case, if I can post the letter print “I can post the letter” in one line, otherwise print “I can't post the letter”.
Sample Input
320 11 2310 10
Sample Output
I can post the letterI can't post the letter
Problem Source
ZSUACM Team Member
题目分析:一次搜索,拓扑即可完成。
参考代码:
#include <iostream>#include <queue>#include <cstring>using namespace std;struct R{ int beg; int end;};int main(){ int n, m; bool vis[200]; while (1) { memset(vis, false, sizeof(vis)); cin >> n; if (n == 0) break; cin >> m; R road[m]; for (int i = 0; i < m; ++ i) { cin >> road[i].beg >> road[i].end; } vis[0] = true; queue<int> q; q.push(0); while (!q.empty() && !vis[n - 1]) { int temp = q.front(); for (int i = 0; i < m; ++ i) { if (temp == road[i].beg) { int tem = road[i].end; if (!vis[tem]) { q.push(tem); vis[tem] = true; } } } q.pop(); } if (vis[n - 1]) { cout << "I can post the letter" << endl; } else { cout << "I can't post the letter" << endl; } }}
- sicily1155. Can I Post the lette
- 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
- 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
- Sicily1155
- hdu 题目4217 Data Structure?(线段树,单点更新)
- sicily1703. Obstacle Course
- sicily1122. Prerequisites?
- sicily1198. Substring
- CHM格式打不开解决方案
- sicily1155. Can I Post the lette
- sicily1625. Binary Clock
- [置顶] sicily1007. To and Fro
- sicily1010. Zipper
- CATransition用于场景转换
- C语言 南阳理工ACM 97.兄弟郊游问题
- win7安装Oracle出错解决方案
- MAC 字体创建和储存(来自于CoreText翻译 Font Creation and Storage)(一)
- Java图像缩略图类库 Thumbnailator 0.4.5 发布