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. Redis安装介绍

    Redis安装介绍 一.Linux版本及配置 1.  Linux版本:Red Hat Enterprise Linux 6虚拟机 2.  配置: 内存:1G:CPU:1核:硬盘:20G 二.Redis ...

  2. CKEditor4.x部署和配置

    CKEditor4.x && JSP 官网下载CKEditor,可选Basic, Standard, Full 解压放置其WebRoot下 JSP中引入以下文件: <script ...

  3. JAXP进行DOM和SAX解析

    1.常用XML的解析方式:DOM和SAX 1)DOM思想:将整个XML加载内存中,形成文档对象,所以对XML操作都对内存中文档对象进行. 2)SAX思想:一边解析,一边处理,一边释放内存资源---不允 ...

  4. linux前四天学习笔记

    以下是在linux培训机构所学的内容,感觉比较乱 MySQL学习笔记MySQL的安装 linux中的超级管理员rootaixocm vnc的退出: F8 MySQL的特点.优点:关系型开源.免费c++ ...

  5. Android 手机进入不了fastboot模式的解决方案

    本方案仅针对linux terminal下刷手机img文件的情况: fastboot的通常流程如下:   adb reboot bootloader  //进入bootloader 模式  fastb ...

  6. [置顶] javascript-基于对象or面向对象?

    最近完成了javascript的初级学习,在这个学习的视频中,我特别注意了两个词,解释性语言和对象,javascript按照我的理解,应该是种解释性语言,他有关于面向对象的思想的体现,但是,他和vb一 ...

  7. vue-auto-focus: 控制自动聚焦行为的 vue 指令

    在网页的表单中,经常需要用程序来控制input和textarea的自动聚焦行为.例如我最近做的一个项目,有个装箱出库的流程,input框自动聚焦的流程如下:页面进入时自动聚焦到订单号输入框->订 ...

  8. NET仿微信Oauth2.0

    这个文章先说一说Oauth2.0的原理,再到应用场景,最后才是代码实现,这样才学会最终的思想,并在应用场景使用,所谓实践出真理. 1,Oauth2.0的原理 OAuth是一个关于授权(authoriz ...

  9. 前端MVC学习笔记(三)——AngularJS服务、路由、内置API、jQueryLite

    一.服务 AngularJS功能最基本的组件之一是服务(Service).服务为你的应用提供基于任务的功能.服务可以被视为重复使用的执行一个或多个相关任务的代码块. AngularJS服务是单例对象, ...

  10. 毕向东_Java基础视频教程第19天_IO流(11~14)

    第19天-11-IO流(字节流File读写操作) import java.io.FileInputStream; import java.io.FileOutputStream; import jav ...