Sicily 1155. Can I Post the lette

典型的图遍历题,任何相关算法都可以解决,我使用的是最基本的宽搜。

Run Time: 0sec
Run Memory: 312KB
Code length: 965Bytes
SubmitTime: 2011-12-24 11:19:47

// Problem#: 1155
// Submission#: 1120671
// 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 <queue>
#include <cstring>
using namespace std;

int main()
{
    int N, M;
    int i, j;
    bool visited[ 200 ];
    bool road[ 200 ][ 200 ];

    while ( cin >> N && N ) {
        memset( visited, false, sizeof( visited ) );
        memset( road, false, sizeof( road ) );
        cin >> M;
        while ( M-- ) {
            cin >> i >> j;
            road[ i ][ j ] = true;
        }

        queue<int> q;
        q.push( 0 );
        visited[ 0 ] = true;
        while ( !q.empty() && !visited[ N - 1 ] ) {
            i = q.front();
            for ( j = 0; j < N; j++ ) {
                if ( road[ i ][ j ] && !visited[ j ] ) {
                    q.push( j );
                    visited[ j ] = true;
                }
            }
            q.pop();
        }
        visited[ N - 1 ] ? cout << "I can post the letter\n": cout << "I can't post the letter\n";
    }

    return 0;

}                                 


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值