1125Stockbroker Grapevine

来源:互联网 发布:天尚网络机顶盒刷机包 编辑:程序博客网 时间:2024/05/22 05:02
暂时没看懂题OTL。。。
**************************华丽分割线************************************
Each pair lists first a number referring to the contact (e.g. a '1' means person number one in the set), followed by the time in minutes taken to pass a message to that person. There are no special punctuation symbols or spacing rules. 
意思是说节名称紧跟着权值。。。
本题意思即输入一个图,从某一点开始遍历,时间最长的值互相比较,输出其最短的起点及时间延迟。
floyd算法的误区:
最外层的k循环是次数既两结点中间的循环,不是第一个结点。
核心算法是:for (int k=1; k<=n; k++) //floyd
    for (int i=1; i<=n; i++) if(i!=k)        for (int j=1; j<=n; j++)                    if(j!=i && j!=k && a[i][j]>a[i][k]+a[k][j]) a[i][j]=a[i][k]+a[k][j];
//floyd之后,a[i][j]代表i到j的最短距离
注意:#define M 999999 //把M改小一点,否则会溢出
原创粉丝点击