文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>1050.Diffuse Secret

1050.Diffuse Secret

时间:2010-11-11  来源:gzzcracker

#include <cstdio>
#include <cstdlib>
#include <iostream>
#define inf 0x3fffffff
using namespace std;

int a[101][101];
int n;

void func() {
    int i, j, k, ans = 0;
    for (k = 1; k <= n; k++)
        for (i = 1; i <= n; i++)
            for (j = 1; j <= n; j++)
                a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
    for (i = 1; i <= n; i++) {
        for (j = 1; j <= n; j++) {
            if (a[i][j] == inf) {
                printf("Secret.\n");
                return;
            }
            ans = max(ans, a[i][j]);
        }
    }
    printf("%d\n", ans);
}

int main(int argc, char** argv) {
    int m, cas = 1;
    int i, j;

    scanf("%d %d", &n, &m);
    while (n) {
        for (i = 1; i <= n; i++)
            for (j = 1; j <= n; j++)
                a[i][j] = i == j ? 0 : inf;
        while (m--) {
            scanf("%d %d", &i, &j);
            a[i][j] = a[j][i] = 1;
        }
        printf("Case %d:\n", cas++);
        func();
        scanf("%d %d", &n, &m);
    }

    return 0;
}


相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载