• <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>
            posts - 7,comments - 3,trackbacks - 0
            Command Network
            Time Limit: 1000MSMemory Limit: 131072K
            Total Submissions: 7267Accepted: 2160

            Description

            After a long lasting war on words, a war on arms finally breaks out between littleken’s and KnuthOcean’s kingdoms. A sudden and violent assault by KnuthOcean’s force has rendered a total failure of littleken’s command network. A provisional network must be built immediately. littleken orders snoopy to take charge of the project.

            With the situation studied to every detail, snoopy believes that the most urgent point is to enable littenken’s commands to reach every disconnected node in the destroyed network and decides on a plan to build a unidirectional communication network. The nodes are distributed on a plane. If littleken’s commands are to be able to be delivered directly from a node A to another node B, a wire will have to be built along the straight line segment connecting the two nodes. Since it’s in wartime, not between all pairs of nodes can wires be built. snoopy wants the plan to require the shortest total length of wires so that the construction can be done very soon.

            Input

            The input contains several test cases. Each test case starts with a line containing two integer N (N ≤ 100), the number of nodes in the destroyed network, and M (M ≤ 104), the number of pairs of nodes between which a wire can be built. The next N lines each contain an ordered pair xi and yi, giving the Cartesian coordinates of the nodes. Then follow M lines each containing two integers i and j between 1 and N (inclusive) meaning a wire can be built between node i and node j for unidirectional command delivery from the former to the latter. littleken’s headquarter is always located at node 1. Process to end of file.

            Output

            For each test case, output exactly one line containing the shortest total length of wires to two digits past the decimal point. In the cases that such a network does not exist, just output ‘poor snoopy’.

            Sample Input

            4 6 
            0 6
            4 6
            0 0
            7 20
            1 2
            1 3
            2 3
            3 4
            3 1
            3 2
            4 3
            0 0
            1 0
            0 1
            1 2
            1 3
            4 1
            2 3

            Sample Output

            31.19 
            poor snoopy

            Source


            裸的最小樹形圖,我就是為了檢驗?zāi)0?...結(jié)果還錯了.....%.2lf在POJ上用G++會莫名的掛掉,所以用C++就行了。
            代碼:
            #include <cstdio>
            #include 
            <cstring>
            #include 
            <cmath>
            #include 
            <algorithm>
            #define MAXN 110
            #define INF 1e30
            using namespace std;

            inline 
            double sqr(double x)
            {
                
            return x * x;
            }

            struct point
            {
                
            double _x, _y;
                
            double dist_with(const point &rh) const
                {
                    
            return sqrt(sqr(_x - rh._x) + sqr(_y - rh._y));
                }
            } po[MAXN];

            double g[MAXN][MAXN];

            int pre[MAXN];
            bool is_out[MAXN];
            int vis[MAXN], vcnt;

            double solve(int n, int root)
            {
                memset(is_out, 
            false, n);
                
            double ans = 0;
                
            while (1)
                {
                    
            int i, j, k;
                    
            for (i = 0; i < n; ++i)
                        
            if (i != root && !is_out[i])
                        {
                            pre[i] 
            = i;
                            
            for (j = 0; j < n; ++j)
                                
            if (!is_out[j] && g[pre[i]][i] > g[j][i])
                                    pre[i] 
            = j;
                            
            if (pre[i] == i) throw false;
                        }
                    
            for (i = 0; i < n; ++i)
                        
            if (i != root && !is_out[i])
                        {
                            j 
            = i;
                            vis[i] 
            = ++vcnt;
                            
            while (vis[pre[j]] != vcnt && pre[j] != root)
                            {
                                j 
            = pre[j];
                                vis[j] 
            = vcnt;
                            }
                            
            if (pre[j] == i)
                                
            break;
                        }
                    
            if (i == n)
                    {
                        
            for (j = 0; j < n; ++j)
                            
            if (j != root && !is_out[j])
                                ans 
            += g[pre[j]][j];
                        
            break;
                    }
                    j 
            = i;
                    
            do
                    {
                        is_out[j] 
            = true;
                        ans 
            += g[pre[j]][j];
                        j 
            = pre[j];
                    } 
            while (j != i);
                    
            for (int j = 0; j < n; ++j)
                        
            if (vis[j] == vcnt)
                            
            for (int k = 0; k < n; ++k)
                                
            if (!is_out[k])
                                {
                                    
            if (g[i][k] > g[j][k])
                                        g[i][k] 
            = g[j][k];
                                    
            if (g[k][i] > g[k][j] - g[pre[j]][j] && g[k][j] != INF)
                                        g[k][i] 
            = g[k][j] - g[pre[j]][j];
                                }
                    is_out[i] 
            = false;
                }
                
            return ans;
            }

            int main()
            {
                
            int n, m;
                
            while (scanf("%d%d"&n, &m) != EOF)
                {
                    
            for (int i = 0; i < n; ++i)
                        
            for (int j = 0; j < n; ++j)
                            g[i][j] 
            = INF;
                    
            for (int i = 0; i < n; ++i)
                        scanf(
            "%lf%lf"&po[i]._x, &po[i]._y);
                    
            for (int i = 0; i < m; ++i)
                    {
                        
            int a, b;
                        scanf(
            "%d%d"&a, &b);
                        
            if (a != b)
                            g[a 
            - 1][b - 1= po[a - 1].dist_with(po[b - 1]);
                    }
                    
            try
                    {
                        printf(
            "%.2lf\n", solve(n, 0));
                    }
                    
            catch (bool)
                    {
                        printf(
            "poor snoopy\n");
                    }
                }
                
            return 0;
            }
            posted on 2011-10-15 22:18 LLawliet 閱讀(163) 評論(0)  編輯 收藏 引用 所屬分類: 圖論
            一本一本久久A久久综合精品 | 超级97碰碰碰碰久久久久最新| 国产精品综合久久第一页| 伊人热人久久中文字幕| 亚洲伊人久久综合影院| 男女久久久国产一区二区三区| 91精品国产91久久| 伊人久久大香线蕉综合5g| 久久久噜噜噜www成人网| 欧美精品一区二区精品久久| 久久婷婷国产剧情内射白浆| 伊人久久免费视频| 亚洲AV无码成人网站久久精品大| 久久精品国产亚洲沈樵| 欧美国产成人久久精品| 久久精品中文字幕一区| 国产精品一区二区久久精品| 久久91精品国产91久| 精品久久久久久无码国产| 久久精品黄AA片一区二区三区| 久久人妻少妇嫩草AV无码蜜桃| 久久天天躁狠狠躁夜夜网站| 久久综合视频网站| 久久这里有精品视频| 久久精品国产精品国产精品污| 久久综合狠狠综合久久综合88| 午夜精品久久久久久久无码| 国产AV影片久久久久久| 91精品国产高清91久久久久久| 国产毛片欧美毛片久久久| 久久中文精品无码中文字幕| 久久被窝电影亚洲爽爽爽| 精品久久人妻av中文字幕| 伊人久久大香线蕉综合影院首页| 一级A毛片免费观看久久精品| 国产福利电影一区二区三区久久老子无码午夜伦不 | 曰曰摸天天摸人人看久久久| 国产V亚洲V天堂无码久久久| 久久婷婷国产综合精品| 久久w5ww成w人免费| 狠狠色丁香婷婷久久综合不卡 |