[SOJ] can I post the letter?
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?的更多相关文章
- Soj题目分类
-----------------------------最优化问题------------------------------------- ----------------------常规动态规划 ...
- [LeetCode] Letter Combinations of a Phone Number 电话号码的字母组合
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- 17. Letter Combinations of a Phone Number
题目: Given a digit string, return all possible letter combinations that the number could represent. A ...
- 【贪心】SOJ 13983
SOJ 13983. Milk Scheduling 这是比赛题,还是作死的我最讨厌的英文题,题目大意就是有n头奶牛,要在喂奶截止时间前给他喂奶并得到相应的含量的牛奶. 一开始的想法就是挑选截止日期的 ...
- 什么是Unicode letter
起因:从一段代码说起 using System; using System.Collections.Generic; using System.Linq; using System.Text; usi ...
- LeetCode——Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- No.017:Letter Combinations of a Phone Number
问题: Given a digit string, return all possible letter combinations that the number could represent.A ...
- SCI/EI期刊投稿 Reply Letter 常用格式总结
SCI/EI期刊投稿Reply Letter常用格式总结 整个论文投稿的过程中,会遇到各种问题,需要我们向主编询问或是回复.下面主要总结了responses to the comme ...
- 【leetcode】 Letter Combinations of a Phone Number(middle)
Given a digit string, return all possible letter combinations that the number could represent. A map ...
随机推荐
- Linux Tweak:交换 Caps_Lock 与 Control_R
很少使用的Caps_Lok键占据着键盘的黄金位置,不仅如此,它还经常被按错. 于是受到程序员神器HHKB启发(如图) 对于我,Linux程序员 + vimer来说: ESC取代`键,极大的方便了VIM ...
- 企业架构研究总结(42)——企业架构与建模之ArchiMate详述(中)
2.4 技术层模型元素 技术层模型元素包括了企业在信息基础设施方面(企业中基本的软硬件环境,包括物理设备.系统软件等为信息化提供基本支持的设施)的各种概念元素,以及他们之间的关系.与应用层模型元素相类 ...
- PrintWriter返回值乱码问题
⑴response.setCharacterEncoding("utf-8"); ⑵response.setContentType("text/html; charset ...
- jQuery Colorbox是一款弹出层
jQuery Colorbox使用教程 jQuery Colorbox是一款弹出层,内容播放插件,效果极佳,最关键的是大小只有10KB,当然我主要是用来弹出图片啦,(之前介绍过jquery Fancy ...
- jQuery实现鼠标移上弹出提示框,移出消失
<TD>里有一行数据 "那片笑声让我想起......" 假设超出规定长度将用......代替, 而现在要通过鼠标移动到......上 显示全部内容,移出则消失.如下图 ...
- hdu1358
Problem Description For each prefix of a given string S with N characters (each character has an ASC ...
- flask tutorial => make a blog :) flask 搭建博客系统从零开始!
please follow the tutorial from the official site :) http://flask.pocoo.org/docs/ You could download ...
- tag标签记录
看到项目代码中有一个自定义的tag标签,想起以前自己写过的标签,竟然忘记的差不多了,手一痒,自己写个简单的tag标签,回顾一下历史知识 首先建一个servlet工程,然后写个index.jsp,项目跑 ...
- Linux系统 nfs 共享及 挂载mount 配置
要把 A服务器(192.168.1.1)的 /home 目录挂载到 B服务器(192.168.1.2)的/mnt目录 我们先在 A 服务器上编辑/etc/exports 文件, 添加下面这行代码 /h ...
- Android---控制设备照相机
本文译自:http://developer.android.com/training/camera/cameradirect.html 本文中,我们讨论如何使用框架API来直接的控制照相机硬件. 直接 ...