• POJ 1125 Stockbroker Grapevine


    #include <iostream>
    #include <fstream>
    #include <string>
    #include <algorithm>
    #include <cstring>
    #include <stack>
    #include <queue>
    //#include <climits>
    #include <cstdio>
    #include <cmath>
    const int INT_MAX = (1 << 21);
    using namespace std;
    int d[105][105];
    struct Node
    {
        int x, y, dis;
    } ans, maxd;
    void init()
    {
        for (int i = 0; i < 105; i++)
            for (int j = 0; j < 105; j++)
            {
                if (i == j)
                    d[i][j] = 0;
                else
                    d[i][j] = INT_MAX;
            }
    }
    void floyd(int n)
    {
        for (int k = 0; k < n; k++)
            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                    if (d[i][j] > d[i][k] + d[k][j])
                        d[i][j] = d[i][k] + d[k][j];
    }
    int main()
    {
        int n, j, i, a, b, m;
    
        while (cin >> n)
        {
            if (!n)
                break;
            init();
            for (i = 0; i < n; i++)
            {
                cin >> m;
                for (j = 0; j < m; j++)
                {
                    cin >> a >> b;
                    d[i][a-1] = b;
                }
            }
            floyd(n);
            ans.dis = INT_MAX;
            for (i = 0; i < n; i++)
            {
                maxd.dis = 0;
                for (j = 0; j < n; j++)
                {
                    if (maxd.dis < d[i][j])
                    {
                        maxd.dis = d[i][j];
                        maxd.x = i;
                        maxd.y = j;
                    }
                }
                if (ans.dis > maxd.dis)
                    ans = maxd;
            }
            if (ans.dis >= INT_MAX)
                cout << "disjoint" << endl;
            else
                cout << ans.x + 1 << ' ' << ans.dis << endl;
    
        }
        return 0;
    }
    

  • 相关阅读:
    zip 中文文件夹为空问题
    webview长按文本区域不显示文字放大镜等方法
    crash
    精疲力尽先生的造访
    告别忙碌的2017,迎来更加忙碌的2018
    传说中的59分!!
    为什么我一定吵不过女人?
    人挪活!
    低谷时,请读书!
    java小入门的感觉
  • 原文地址:https://www.cnblogs.com/dollarzhaole/p/3188901.html
Copyright © 2020-2023  润新知