• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            poj1125

            Stockbroker Grapevine

            Time Limit: 1000MS Memory Limit: 10000K
            Total Submissions: 18729 Accepted: 10120

            Description

            Stockbrokers are known to overreact to rumours. You have been contracted to develop a method of spreading disinformation amongst the stockbrokers to give your employer the tactical edge in the stock market. For maximum effect, you have to spread the rumours in the fastest possible way.

            Unfortunately for you, stockbrokers only trust information coming from their "Trusted sources" This means you have to take into account the structure of their contacts when starting a rumour. It takes a certain amount of time for a specific stockbroker to pass the rumour on to each of his colleagues. Your task will be to write a program that tells you which stockbroker to choose as your starting point for the rumour, as well as the time it will take for the rumour to spread throughout the stockbroker community. This duration is measured as the time needed for the last person to receive the information.

            Input

            Your program will input data for different sets of stockbrokers. Each set starts with a line with the number of stockbrokers. Following this is a line for each stockbroker which contains the number of people who they have contact with, who these people are, and the time taken for them to pass the message to each person. The format of each stockbroker line is as follows: The line starts with the number of contacts (n), followed by n pairs of integers, one pair for each contact. 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.

            Each person is numbered 1 through to the number of stockbrokers. The time taken to pass the message on will be between 1 and 10 minutes (inclusive), and the number of contacts will range between 0 and one less than the number of stockbrokers. The number of stockbrokers will range from 1 to 100. The input is terminated by a set of stockbrokers containing 0 (zero) people.

            Output

            For each set of data, your program must output a single line containing the person who results in the fastest message transmission, and how long before the last person will receive any given message after you give it to this person, measured in integer minutes.
            It is possible that your program will receive a network of connections that excludes some persons, i.e. some people may be unreachable. If your program detects such a broken network, simply output the message "disjoint". Note that the time taken to pass the message from person A to person B is not necessarily the same as the time taken to pass it from B to A, if such transmission is possible at all.

            Sample Input

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

            Sample Output

            3 2
            3 10
            構圖,求出從一個頂點到其余頂點最遠的距離,然后求每個頂點這樣做之后的最小值,即為最小時間
            顯然求多源最短路,題目中給出的數據范圍是1-100,floyd正合適,O(N^3)
            寫好之后交了兩邊之后都wa,不明白
            后來自習看了半天,發現找完最短路f[][]時候,查找答案過程中是在map[][]中找的,壞習慣害死人啊,
            這里說一下,其實只用一個數組記錄圖就行,在起基礎上操作即可
            這次的樣例夠陰險的,找完最短路后矩陣居然沒變……
             1#include<stdio.h>
             2#include<string.h>
             3#include<math.h>
             4#define MAX 100
             5#define M 210000000
             6int point,ans;
             7int n,map[MAX+5][MAX+5],f[MAX+5][MAX+5];
             8void init()
             9{
            10    int i,j,t;
            11    int a,b;
            12    for (i=0; i<=n ; i++ )
            13        for (j=0; j<=n ; j++ )
            14        {
            15            map[i][j]=M;
            16        }

            17    for (i=1; i<=n ; i++ )
            18    {
            19        scanf("%d",&t);
            20        for (j=1; j<=t; j++)
            21        {
            22            scanf("%d%d",&a,&b);
            23            map[i][a]=b;
            24        }

            25    }

            26
            27    for (i=1; i<=n ; i++ )
            28        for (j=1; j<=n ; j++ )
            29            f[i][j]=map[i][j];
            30}

            31int work()
            32{
            33    int min;
            34    int i,j,k;
            35    for (k=1; k<=n ; k++ )
            36        for (i=1; i<=n ; i++ )
            37            for (j=1; j<=n ; j++ )
            38                if ((i!=j)&&(j!=k)&&(k!=i))
            39                    if (f[i][j]>f[i][k]+f[k][j])
            40                    {
            41                        f[i][j]=f[i][k]+f[k][j];
            42                    }

            43    ans=M;
            44    for (i=1; i<=n ; i++ )
            45    {
            46        min=0;
            47        for (j=1; j<=n ; j++ )
            48            if (f[i][j]>min&&i!=j)
            49            {
            50                min=f[i][j];
            51            }

            52        if (min<M)
            53        {
            54            if (min<ans)
            55            {
            56                point=i;
            57                ans=min;
            58            }

            59        }

            60    }

            61}

            62int main()
            63{
            64    int flag;
            65    int i;
            66    while (scanf("%d",&n)!=EOF&&n!=0)
            67    {
            68        init();
            69        work();
            70        if (ans>M)
            71            printf("disjoint\n");
            72        else
            73            printf("%d %d\n",point,ans);
            74    }

            75    return 0;
            76}

            77

            posted on 2012-02-07 23:31 jh818012 閱讀(245) 評論(0)  編輯 收藏 引用

            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導航

            統計

            常用鏈接

            留言簿

            文章檔案(85)

            搜索

            最新評論

            • 1.?re: poj1426
            • 我嚓,,輝哥,,居然搜到你的題解了
            • --season
            • 2.?re: poj3083
            • @王私江
              (8+i)&3 相當于是 取余3的意思 因為 3 的 二進制是 000011 和(8+i)
            • --游客
            • 3.?re: poj3414[未登錄]
            • @王私江
              0ms
            • --jh818012
            • 4.?re: poj3414
            • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
            • --王私江
            • 5.?re: poj1426
            • 評論內容較長,點擊標題查看
            • --王私江
            国产精品日韩欧美久久综合| 久久精品国产亚洲AV高清热| 久久被窝电影亚洲爽爽爽| 久久亚洲高清观看| 久久综合伊人77777| 亚洲乱码精品久久久久..| 97精品国产91久久久久久| 国产成人精品久久亚洲| 伊人久久精品无码二区麻豆| 久久天堂电影网| 精产国品久久一二三产区区别| 国产精品久久午夜夜伦鲁鲁| 久久无码AV中文出轨人妻| 国产精品女同久久久久电影院| 综合久久久久久中文字幕亚洲国产国产综合一区首| 亚洲国产高清精品线久久| 国产人久久人人人人爽| 久久精品国产亚洲AV影院 | 日本人妻丰满熟妇久久久久久| 久久精品国产福利国产秒| 狠狠色狠狠色综合久久| 久久人妻少妇嫩草AV无码蜜桃| 久久精品国产69国产精品亚洲 | 精品免费tv久久久久久久| 亚洲精品第一综合99久久| 99热精品久久只有精品| 国产精品久久网| 色88久久久久高潮综合影院| 婷婷久久综合| 伊人久久成人成综合网222| 久久久久亚洲AV无码专区网站| 丁香五月综合久久激情| 久久777国产线看观看精品| 国内精品久久久久影院日本| 国产麻豆精品久久一二三| 2022年国产精品久久久久| 精品久久久久久久无码| 久久久久人妻精品一区二区三区| 人妻精品久久无码区| 久久精品亚洲中文字幕无码麻豆| 国产精品美女久久久久|