• HDU 1869 六度分离 最短路


    六度分离
    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
     

    Description

    1967年,美国著名的社会学家斯坦利·米尔格兰姆提出了一个名为“小世界现象(small world phenomenon)”的著名假说,大意是说,任何2个素不相识的人中间最多只隔着6个人,即只用6个人就可以将他们联系在一起,因此他的理论也被称为“六度分离”理论(six degrees of separation)。虽然米尔格兰姆的理论屡屡应验,一直也有很多社会学家对其兴趣浓厚,但是在30多年的时间里,它从来就没有得到过严谨的证明,只是一种带有传奇色彩的假说而已。 

    Lele对这个理论相当有兴趣,于是,他在HDU里对N个人展开了调查。他已经得到了他们之间的相识关系,现在就请你帮他验证一下“六度分离”是否成立吧。

    Input

    本题目包含多组测试,请处理到文件结束。 
    对于每组测试,第一行包含两个整数N,M(0<N<100,0<M<200),分别代表HDU里的人数(这些人分别编成0~N-1号),以及他们之间的关系。 
    接下来有M行,每行两个整数A,B(0<=A,B<N)表示HDU里编号为A和编号B的人互相认识。 
    除了这M组关系,其他任意两人之间均不相识。 

    Output

    对于每组测试,如果数据符合“六度分离”理论就在一行里输出"Yes",否则输出"No"。

    Sample Input

    8 7
    0 1
    1 2
    2 3
    3 4
    4 5
    5 6
    6 7
    8 8
    0 1
    1 2
    2 3
    3 4
    4 5
    5 6
    6 7
    7 0

    Sample Output

    Yes
    Yes


    数据很小 用floyd硬上就行
    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <algorithm>
    #include <queue>
    #include <vector>
    #include <iomanip>
    #include <math.h>
    #include <map>
    using namespace std;
    #define FIN     freopen("input.txt","r",stdin);
    #define FOUT    freopen("output.txt","w",stdout);
    #define INF     0x3f3f3f3f
    #define lson    l,m,rt<<1
    #define rson    m+1,r,rt<<1|1
    typedef long long LL;
    
    int Map[205][205];
    int n,m;
    
    int llss(){
        for(int z=0;z<n;z++)
           for(int i=0;i<n;i++)
               for(int j=0;j<n;j++){
                    if(Map[i][j]>Map[i][z]+Map[z][j])
                        Map[i][j]=Map[i][z]+Map[z][j];
                }
    
        int flag=1;
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++){
                if(Map[i][j]>7)  flag=0;
            }
        return flag;
    }
    
    int main()
    {
        //FIN
        int st,ed;
        int s,e;
        while(~scanf("%d%d",&n,&m))
        {
            memset(Map,INF,sizeof(Map));
            for(int i=0;i<n;i++){
                Map[i][i]=0;
            }
            for(int i=1;i<=m;i++){
                scanf("%d%d",&st,&ed);
                Map[ed][st]=Map[st][ed]=1;
            }
            if(llss()) printf("Yes
    ");
            else  printf("No
    ");
    
        }
    }
    

      

  • 相关阅读:
    tp5 生成数据表
    tp5 事务
    时间
    api json
    php 函数学习
    win7 安装Ubuntu18.04 双系统后无法引导win7
    vite笔记
    tp5 excel导出
    tp5 sql查询
    idea 停止运行程序
  • 原文地址:https://www.cnblogs.com/Hyouka/p/5751195.html
Copyright © 2020-2023  润新知