1155. Can I Post the letter

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

3
2
0 1
1 2
3
1
0 1
0

Sample Output

I can post the letter
I can't post the letter 利用Dijiskra算法解决问题
#include<iostream>
#include<memory>
using namespace std; const int MAX = 205;
int edge[MAX][MAX];
bool visited[MAX];
int n, m; void DFS(int current)
{
for(int i=0;i<n;i++)
{
if(!visited[i]&&edge[current][i])
{
visited[i]=true;
DFS(i);
}
}
} int main()
{
while(cin>>n&&n!=0&&cin>>m)
{
memset(edge, 0, sizeof(edge));
memset(visited, false, sizeof(visited));
int a, b; for(int i=0;i<m;i++)
{
cin>>a>>b;
edge[a][b]=1;
edge[b][a]=1;
}
visited[0]=true; DFS(0); if(visited[n-1])cout<<"I can post the letter\n";
else cout<<"I can't post the letter\n";
} return 0;
}

[SOJ] can I post the letter?的更多相关文章

  1. Soj题目分类

    -----------------------------最优化问题------------------------------------- ----------------------常规动态规划 ...

  2. [LeetCode] Letter Combinations of a Phone Number 电话号码的字母组合

    Given a digit string, return all possible letter combinations that the number could represent. A map ...

  3. 17. Letter Combinations of a Phone Number

    题目: Given a digit string, return all possible letter combinations that the number could represent. A ...

  4. 【贪心】SOJ 13983

    SOJ 13983. Milk Scheduling 这是比赛题,还是作死的我最讨厌的英文题,题目大意就是有n头奶牛,要在喂奶截止时间前给他喂奶并得到相应的含量的牛奶. 一开始的想法就是挑选截止日期的 ...

  5. 什么是Unicode letter

    起因:从一段代码说起 using System; using System.Collections.Generic; using System.Linq; using System.Text; usi ...

  6. LeetCode——Letter Combinations of a Phone Number

    Given a digit string, return all possible letter combinations that the number could represent. A map ...

  7. No.017:Letter Combinations of a Phone Number

    问题: Given a digit string, return all possible letter combinations that the number could represent.A ...

  8. SCI/EI期刊投稿 Reply Letter 常用格式总结

    SCI/EI期刊投稿Reply Letter常用格式总结          整个论文投稿的过程中,会遇到各种问题,需要我们向主编询问或是回复.下面主要总结了responses to the comme ...

  9. 【leetcode】 Letter Combinations of a Phone Number(middle)

    Given a digit string, return all possible letter combinations that the number could represent. A map ...

随机推荐

  1. C++指针数组和指向指针的指针

    指针数组 定义: 如果一个 数组,其元素均为指针型数据,该数组为指针数组,也就是说,指针数组中的每一个元素相当于一个指针变量,它的值都是地址. 形式: 一维指针数组的定义形式为: int[类型名] * ...

  2. HTML文档类型

    在HMTL5中页面的最顶端代码就是: <!DOCTYPE html> 为何要如此定义.书写呢? 首先引入一个概念:文档类型,英译为:Document type,缩写成:doctype. 文 ...

  3. new关键字

    Javascript的实例化与继承:请停止使用new关键字   本文同时也发表在我另一篇独立博客 <Javascript的实例化与继承:请停止使用new关键字>(管理员请注意!这两个都是我 ...

  4. .NET开发规范教程

    .NET开发规范教程 这是1年多以前我在公司所做讲座的讲义,现在与园友们分享,欢迎拿去使用.一起讨论.文中有若干思考题,对园友们是小菜一碟.另有设计模式讲义一篇,随后发布. 1 概述 1.1 意义 “ ...

  5. CentOS中安装Python-PIP

    wget http://pypi.python.org/packages/source/p/pip/pip-1.0.2.tar.gz tar zxf pip-1.0.2.tar.gz cd pip-1 ...

  6. appfog java jdbc mysql连接

    本来用得好好的openshift被墙了,无奈只能找过一个免费的空间.同学推荐appfog,appfog的确是一个很好用的空间,支持几乎所有主流的技术.我自己喜欢写点java,刚好我就开始使用了.app ...

  7. NCache:最新发布的.NET平台分布式缓存系统

    NCache:最新发布的.NET平台分布式缓存系统在等待Microsoft完成Velocity这个.NET平台下的分布式内存缓存系统的过程中,现在让我们将目光暂时投向其他已经有所建树的软件开发商.Al ...

  8. Bottle GET method. Request

    python bottle framework #!/usr/bin/python # -*- coding utf-8 -*- from bottle import route, run, debu ...

  9. TFS体系结构和概念

    TFS体系结构和概念 TFS是Team Fundation Server的简称,是微软VSTS的一部分,它是Microsoft应用程序生命周期管理(ALM)工具的核心协作平台,简单的说它是管理和开发软 ...

  10. listView 分页加载数据

    Android应用 开发中,采用ListView组件来展示数据是很常用的功能,当一个应用要展现很多的数据时,一般情况下都不会把所有的数据一次就展示出来,而是通过分页 的形式来展示数据,个人觉得这样会有 ...