[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 ...
随机推荐
- jQuery event的复制粘贴的坑
jQuery为了兼容性会把系统暴露出来的event重新整理一遍,但是复制粘贴的event就被丢掉了. 所以要在所有原生浏览器想实现复制粘贴,大家都用flash实现了.其实只要用原生的方法捕获事件就ok ...
- Oracle查询错误分析:ORA-01791:不是SELECTed表达式
表结构如下: create table HH_BOOK_GOOD ( ID VARCHAR2(32) not null, BOOKID VARCHAR2(32) not null, GOODID VA ...
- Devexpress XtraReports 交叉报表
[原创]Devexpress XtraReports 系列 5 创建交叉报表 昨天我们已经介绍了如何创建多栏报表,详见:[原创]Devexpress XtraReports 系列 4 创建多栏报表 ...
- Single Image Haze Removal Using Dark Channel Prior
<Single Image Haze Removal Using Dark Channel Prior>一文中图像去雾算法的原理.实现.效果及其他. Posted on 2013-08-2 ...
- 初探原生js根据json数据动态创建table
初探原生js根据json数据动态创建table 小生以实习生的职位进入了一家非纯软件的公司做asp.net开发,大半个月下来发现公司里居然没有前端工程师,这令我很诧异,跟着公司做项目,发现前端后台没有 ...
- python实现基于CGI的Web应用
python实现基于CGI的Web应用 本文用一个“网上书店”的web应用示例,简要介绍如何用Python实现基于CGI标准的Web应用,介绍python的cgi模块.cigtb模块对编写CGI脚本提 ...
- .Net 中的反射机制
.Net 中的反射机制 概述反射 通过反射可以提供类型信息,从而使得我们开发人员在运行时能够利用这些信息构造和使用对象. 反射机制允许程序在执行过程中动态地添加各种功能. 运行时类型标识 运行时类型标 ...
- 从零开始学C++之IO流类库(二):文件流(fstream, ifstream, ofstream)的打开关闭、流状态
一.文件流 ofstream,由ostream派生而来,用于写文件 ifstream,由istream派生而来, 用于读文件 fstream,由iostream派生而来,用于读写文件 二.打开文件 说 ...
- 软件设计师.NET认证考试测试卷(试题及答案)
软件设计师.NET认证考试测试卷 注意事项:用蓝.黑色钢笔答题.保持卷面整洁. 得分 阅卷人 一.单项选择(40分,每小题1分) 1.以下标识符中不全是关键字的是(D ) A.case for in ...
- 命令版本git 分支篇-----不断更新中
最近应用开发的过程中出现了一个小问题,顺便记录一下原因和方法--命令版本 开发中想看看过去某个版本的代码,我们先查看log git log commit f224a720b8192165a4e70f2 ...