• <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>

            poj2485

            Highways

            Time Limit: 1000MS Memory Limit: 65536K
            Total Submissions: 14220 Accepted: 6620

            Description

            The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public highways. So the traffic is difficult in Flatopia. The Flatopian government is aware of this problem. They're planning to build some highways so that it will be possible to drive between any pair of towns without leaving the highway system.

            Flatopian towns are numbered from 1 to N. Each highway connects exactly two towns. All highways follow straight lines. All highways can be used in both directions. Highways can freely cross each other, but a driver can only switch between highways at a town that is located at the end of both highways.

            The Flatopian government wants to minimize the length of the longest highway to be built. However, they want to guarantee that every town is highway-reachable from every other town.

            Input

            The first line of input is an integer T, which tells how many test cases followed.
            The first line of each case is an integer N (3 <= N <= 500), which is the number of villages. Then come N lines, the i-th of which contains N integers, and the j-th of these N integers is the distance (the distance should be an integer within [1, 65536]) between village i and village j. There is an empty line after each test case.

            Output

            For each test case, you should output a line contains an integer, which is the length of the longest road to be built such that all the villages are connected, and this value is minimum.

            Sample Input

            1
            3
            0 990 692
            990 0 179
            692 179 0

            Sample Output

            692
            

            Hint

            Huge input,scanf is recommended.

            這次還是1A,爽歪歪啊,也沒(méi)想到

            那個(gè)這個(gè)題求的是讓任意兩個(gè)城市之間有路徑

            并且使得最長(zhǎng)的公路的距離最短

            所以應(yīng)該讓任意兩個(gè)城市之間的路盡量短,這符合最小生成樹(shù)的性質(zhì)

            還是用的該過(guò)的prim的代碼,稍微修改了下,還是矩陣存的,費(fèi)內(nèi)存啊

            其實(shí)我覺(jué)得記錄邊的話,并查集優(yōu)化的kruskal可能更好用
             1#include<stdio.h>
             2#include<string.h>
             3#include<math.h>
             4#define MAX 600
             5int map[MAX][MAX],ans;
             6int bian[1000][2],v[MAX];
             7int n;
             8short vis[MAX];
             9void init()
            10{
            11    int i,j;
            12    scanf("%d",&n);
            13    for (i=1;i<=n ;i++ )
            14    {
            15        for (j=1;j<=n ;j++ )
            16        {
            17            scanf("%d",&map[i][j]);
            18        }

            19    }

            20}

            21void prim()
            22{
            23    int i,j,k,dmin;
            24    memset(vis,0,sizeof(vis));
            25    vis[1]=1;
            26    v[1]=1;
            27    for (i=2;i<=n;i++)
            28    {
            29        dmin=0x7fffffff;
            30        for (k=1;k<=i-1 ;k++ )
            31        {
            32            for (j=1;j<=n ;j++ )
            33                if ((!vis[j])&&(j!=v[k])&&(map[v[k]][j]<dmin))
            34            {
            35                dmin=map[v[k]][j];
            36                v[i]=j;
            37                bian[i-1][0]=v[k];
            38                bian[i-1][1]=j;
            39            }

            40        }

            41        vis[v[i]]=1;
            42    }

            43    ans=0;
            44    for (i=1;i<=n-1 ;i++ )
            45        if (ans<map[bian[i][0]][bian[i][1]])
            46        {
            47            ans=map[bian[i][0]][bian[i][1]];
            48        }

            49}

            50int main()
            51{
            52    int t;
            53    scanf("%d",&t);
            54    while (t)
            55    {
            56        init();
            57        prim();
            58        printf("%d\n",ans);
            59        t--;
            60    }

            61    return 0;
            62}

            63


            posted on 2012-02-14 21:21 jh818012 閱讀(210) 評(píng)論(0)  編輯 收藏 引用


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


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

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿

            文章檔案(85)

            搜索

            最新評(píng)論

            • 1.?re: poj1426
            • 我嚓,,輝哥,,居然搜到你的題解了
            • --season
            • 2.?re: poj3083
            • @王私江
              (8+i)&3 相當(dāng)于是 取余3的意思 因?yàn)?3 的 二進(jìn)制是 000011 和(8+i)
            • --游客
            • 3.?re: poj3414[未登錄](méi)
            • @王私江
              0ms
            • --jh818012
            • 4.?re: poj3414
            • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
            • --王私江
            • 5.?re: poj1426
            • 評(píng)論內(nèi)容較長(zhǎng),點(diǎn)擊標(biāo)題查看
            • --王私江
            久久精品一区二区三区不卡| 久久99热这里只有精品国产 | 久久婷婷激情综合色综合俺也去| 午夜精品久久久久成人| 97精品国产97久久久久久免费| 久久精品国产久精国产思思 | 热久久视久久精品18| 99蜜桃臀久久久欧美精品网站| 久久亚洲精品中文字幕| 国产免费久久久久久无码| 久久国语露脸国产精品电影| av无码久久久久不卡免费网站 | 久久精品免费一区二区| 国内精品伊人久久久久| 欧美伊人久久大香线蕉综合| 伊人久久大香线蕉精品| 亚洲∧v久久久无码精品| 久久最新免费视频| 91亚洲国产成人久久精品网址 | 久久国产香蕉视频| 日韩AV无码久久一区二区 | 久久综合狠狠综合久久| 久久影院久久香蕉国产线看观看| 国内精品久久久久久99蜜桃| 欧美激情精品久久久久久久| 美女写真久久影院| 久久精品aⅴ无码中文字字幕不卡 久久精品aⅴ无码中文字字幕重口 | 亚洲精品无码久久一线| 久久福利片| 男女久久久国产一区二区三区| 国产精品美女久久久免费| 国产99精品久久| 久久精品这里热有精品| 亚洲国产精品无码久久久不卡| 久久亚洲AV无码精品色午夜| 亚洲AⅤ优女AV综合久久久| 久久久这里有精品中文字幕| www亚洲欲色成人久久精品| 国产精品亚洲美女久久久| 99精品伊人久久久大香线蕉| 国内精品久久久久久久影视麻豆|