Sicily1155

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

320 11 2310 10

Sample Output

I can post the letterI can't post the letter

Problem Source

ZSUACM Team Member



水题一条。时间很多。暴力刷一遍都是可以的。我用了 Warshall 算法简单不费力。


// Problem#: 1155
// Submission#: 2182142
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include<iostream>
#include<cstdio>


using namespace std;


int main()
{
    int i,j,k;
    int a,b;
    int n,m;


    scanf("%d",&n);


    while(n != 0)
    {
        int matrix[n][n];
        for(i = 0; i < n; i++)
        {
            for(j = 0; j < n; j++)
            {
                matrix[i][j] = 0;
            }
        }


        scanf("%d",&m);
        for(i = 0; i < m; i++)
        {
            scanf("%d %d",&a,&b);
            matrix[a][b] = 1;
        }


        for(i = 0; i < n; i++)
        {
            for(j = 0; j < n; j++)
            {
                if(matrix[j][i] == 1)
                {
                    for(k = 0; k < n; k++)
                    {
                        if(matrix[i][k] == 1)
                            matrix[j][k] = 1;
                    }
                }
            }
        }


        if(matrix[0][n-1] == 1)
            cout << "I can post the letter" << endl;
        else
            cout << "I can't post the letter" << endl;


        scanf("%d",&n);
    }


    return 0;
}                                 



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值