Sicily 1155 Can I Post the letter

来源:互联网 发布:ubuntu图形界面切换 编辑:程序博客网 时间:2024/05/12 19:36

有向图判断两点之间是否可达,直接上沃舍尔算法。

#include <stdio.h>int main(){    int n,i,j,k,m;    int b,c;    int a[200][200];    scanf( "%d",&n );    while (n!=0) {        for ( i=0;i<n;i++ ) {            for ( j=0;j<n;j++ ) {                a[i][j]=0;            }        }        scanf( "%d",&m );        for ( i=0;i<m;i++ ) {            scanf( "%d%d",&b,&c );            a[b][c]=1;        }        for ( i=0;i<n;i++ ) {            for ( j=0;j<n;j++ ) {                if ( a[j][i]==1 ) {                    for ( k=0;k<n;k++ ) {                        if (a[i][k]==1)                            a[j][k]=1;                    }                }            }        }        if ( a[0][n-1]==1 ) {            printf( "I can post the letter\n" );        }        else {            printf( "I can't post the letter\n" );        }        scanf( "%d",&n );    }    return 0;} 

原创粉丝点击