[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 ...
随机推荐
- cocos2d-x 通过socket实现http下载及断点续传的实现
cocos2d-x 通过socket实现http下载及断点续传的实现 代码未经进一步的整理,可能比较混乱. 首先,2dx的socket库由BSSocket组成.可跨平台,在windows上已验证. 1 ...
- Java 简单工厂模式
首先 定义一接口 package com.org; public interface SampleInterface { public void print(String s); } 定义两个接口的实 ...
- HDU3930(离散对数与原根)
题目:Broot 题意:给出k,m,newx的值,求方程x^k(mod m)=newx的解,其中m为素数. 解法步骤: (1)先暴力求m的原根g (2)大步小步求g^t1(mod m)=newx (3 ...
- java生成PDF文件(itext)
itextpdf-5.4.3.jar下载地址: http://www.kuaipan.cn/file/id_58980483773788178.htm 导入itextpdf-5.4.3.jar ToP ...
- Page_Load接收随机参数放到字典类中
Page_Load接收随机参数放到字典类中,可以用作签名.普通的接收url的参数可以用作下面这种模式: int appid =Convert.ToInt32(param["appid&qu ...
- Linux centOS本地DNS安装
centOS本地DNS安装 在centOS里最常用的DNS服务工具应该是bind了.下面就以bind为例做一个DNS服务. 首先查看bind 是否已经安装 Rpm -qa | gerp bind 如果 ...
- Ubuntu 下的环境变量配置
网上很多配置jdk环境变量的方法,但是几乎都会下次重启电脑就失效,或者时不时的失效.下面教你一招 JDK环境变量配置如下: 执行命令sudo gedit /etc/environment,在打开的编辑 ...
- linux下搭建svn本地服务器
在linux下搭建svn本地服务器可以很好的管理自己的代码,具体过程如下: # mkdir svn_local # cd svn_local # svnadmin create led_diplay ...
- Android RecyclerView完全解析
RecyclerView完全解析 (一) 前言 话说RecyclerView已经面市很久,也在很多应用中得到广泛的使用,在整个开发者圈子里面也拥有很不错的口碑,那说明RecyclerView拥有比Li ...
- jquery开头
jQuery(function(){});jQuery().ready(function(){}); 绑定点击事件: jQuery('#temp').click(function() {}); $(d ...