青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

posts - 7,comments - 3,trackbacks - 0
The Unique MST
Time Limit: 1000MS
Memory Limit: 10000K
Total Submissions: 11943
Accepted: 4112

Description

Given a connected undirected graph, tell if its minimum spanning tree is unique.

Definition 1 (Spanning Tree): Consider a connected, undirected graph G = (V, E). A spanning tree of G is a subgraph of G, say T = (V', E'), with the following properties:
1. V' = V.
2. T is connected and acyclic.

Definition 2 (Minimum Spanning Tree): Consider an edge-weighted, connected, undirected graph G = (V, E). The minimum spanning tree T = (V, E') of G is the spanning tree that has the smallest total cost. The total cost of T means the sum of the weights on all the edges in E'.

Input

The first line contains a single integer t (1 <= t <= 20), the number of test cases. Each case represents a graph. It begins with a line containing two integers n and m (1 <= n <= 100), the number of nodes and edges. Each of the following m lines contains a triple (xi, yi, wi), indicating that xi and yi are connected by an edge with weight = wi. For any two nodes, there is at most one edge connecting them.

Output

For each input, if the MST is unique, print the total cost of it, or otherwise print the string 'Not Unique!'.

Sample Input

2 
3 3
1 2 1
2 3 2
3 1 3
4 4
1 2 2
2 3 2
3 4 2
4 1 2

Sample Output

3 
Not Unique!

Source

POJ Monthly--2004.06.27 srbga@P

代碼:
#include <iostream>
#include 
<cstdio>
#include 
<cstring>
#include 
<algorithm>
using namespace std;

typedef 
struct
{
    
int x, y, w;
} edge;

edge s[
10010];
int top, t[10010];

bool cmp(edge a, edge b)
{
    
return a.w < b.w;
}

int kru(int n, int m, int x)
{
    
int i, j, a, b, tag[110], tem, sum, k;
    
for (i = 0; i < n; ++i)
    {
        tag[i] 
= i;
    }
    k 
= 1, j = 0, sum = 0;
    
while (k < n)
    {
        a 
= s[j].x - 1;
        b 
= s[j].y - 1;
        
if (j == x)
        {
            j
++;
            
continue;
        }
        
if (tag[a] != tag[b])
        {
            
if (x == -1)
            {
                t[top] 
= j;
                top
++;
            }
            tem 
= tag[b];
            k
++, sum += s[j].w;
            
for (i =  0; i < n; ++i)
            {
                
if (tag[i] == tem)
                {
                    tag[i] 
= tag[a];
                }
            }
        }
        j
++;
    }
    
return sum;
}
int main()
{
    
int p, n, m, cmin;
    scanf(
"%d"&p);
    
while (p--)
    {
        
int flag = 1;
        scanf(
"%d%d"&n, &m);
        
for (int i = 0; i < m; ++i)
            scanf(
"%d%d%d"&s[i].x, &s[i].y, &s[i].w);
        sort(s, s 
+ m, cmp);
        top 
= 0;
        
int min = kru(n, m, -1);
        
int key = top;
        
for (int l = 0; l < key; ++l)
        {
            cmin 
= kru(n, m, t[l]);
            
if (cmin == min)
            {
                flag 
= 0;
                printf(
"Not Unique!\n");
                
break;
            }
        }
        
if (flag)
        printf(
"%d\n", min);
    }
    
return 0;
}
posted on 2011-10-17 21:07 LLawliet 閱讀(278) 評(píng)論(0)  編輯 收藏 引用 所屬分類: 圖論

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


青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            欧美极品在线播放| 欧美午夜一区| 一区二区在线免费观看| 久久国产免费看| 欧美在线观看www| 激情综合在线| 欧美高清视频| 欧美日韩不卡| 亚洲欧美日韩网| 午夜精品久久久久久久久久久久| 国产精品青草综合久久久久99| 新67194成人永久网站| 午夜精品久久久久99热蜜桃导演| 国产区在线观看成人精品| 久久免费的精品国产v∧| 久久久久久色| 日韩亚洲精品在线| 亚洲视频自拍偷拍| 国产一区二区三区高清| 你懂的网址国产 欧美| 欧美二区在线看| 亚洲一二三区在线观看| 午夜精品久久久久久| 激情视频亚洲| 亚洲精品一区二区三区99| 国产精品一区久久久| 欧美aa在线视频| 欧美日韩综合网| 久久亚洲国产成人| 欧美精品一区二区三区很污很色的| 亚洲香蕉成视频在线观看| 久久精品123| 在线综合视频| 久久国产手机看片| 亚洲天堂第二页| 久久人人爽人人爽爽久久| 中文精品视频一区二区在线观看| 性亚洲最疯狂xxxx高清| 亚洲伦理自拍| 欧美在线啊v一区| 亚洲天堂免费在线观看视频| 久久久精品999| 亚洲一区二区久久| 麻豆国产va免费精品高清在线| 亚洲欧美中文在线视频| 欧美mv日韩mv亚洲| 久久人人97超碰国产公开结果 | 亚洲一级电影| 久久综合五月| 久久精品国产2020观看福利| 欧美日韩一区二区三区免费看| 美女国产精品| 国产婷婷97碰碰久久人人蜜臀| 日韩视频在线观看国产| 亚洲高清在线观看一区| 久久er99精品| 欧美与欧洲交xxxx免费观看| 欧美日韩中文| 亚洲欧洲一区二区在线观看 | 欧美在线影院| 欧美在线视频一区二区三区| 欧美日韩精品系列| 亚洲激情电影在线| 亚洲激情第一区| 久久免费视频一区| 久久免费黄色| 一区二区三区在线免费观看| 欧美一区二区三区免费观看视频| 午夜国产欧美理论在线播放| 欧美调教视频| 一区二区欧美日韩视频| 一区二区国产精品| 欧美日韩免费一区二区三区| 亚洲伦理久久| 亚洲在线日韩| 国产精品嫩草影院av蜜臀| 中文精品一区二区三区 | 国产精品亚洲成人| 亚洲一二三级电影| 欧美一区二区三区成人| 国产欧美日韩另类一区 | 欧美大成色www永久网站婷| 激情久久婷婷| 美女诱惑一区| 亚洲精品国偷自产在线99热| 在线午夜精品自拍| 国产精品久久99| 欧美一区二区久久久| 久久久久国产成人精品亚洲午夜| 国产一区二区三区成人欧美日韩在线观看| 欧美一进一出视频| 欧美freesex交免费视频| 亚洲精品日韩精品| 欧美午夜久久| 久久国产精品亚洲77777| 欧美xxx在线观看| 夜夜精品视频| 国产色婷婷国产综合在线理论片a| 欧美在线免费观看视频| 欧美黄色片免费观看| 亚洲综合久久久久| 黄色成人免费网站| 欧美日韩三级| 欧美一级理论片| 亚洲国产精品成人精品| 亚洲一区二区视频| 在线成人中文字幕| 欧美三级电影大全| 久久美女艺术照精彩视频福利播放| 亚洲欧洲日本mm| 久久激情视频久久| 一本色道久久综合亚洲精品婷婷| 国产精品亚洲不卡a| 免费看黄裸体一级大秀欧美| 亚洲一级二级| 欧美大色视频| 久久久91精品国产| 国产精品99久久久久久久久久久久| 国产在线一区二区三区四区| 欧美连裤袜在线视频| 久久国产一区| 亚洲综合首页| 日韩一区二区精品视频| 模特精品在线| 久久精品一区二区| 亚洲一区二区三区视频| 亚洲黄色av| 国产一区二区三区在线免费观看| 欧美日韩精品久久久| 欧美1区2区视频| 久久成人羞羞网站| 午夜精品999| 亚洲无吗在线| 日韩午夜在线视频| 亚洲国产精品激情在线观看| 久久人体大胆视频| 欧美一区二区三区免费大片| 在线视频日韩精品| 亚洲美女色禁图| 亚洲精品国产精品国自产在线| 国产一区二区三区奇米久涩| 国产精品网站在线播放| 国产精品久久精品日日| 欧美日韩日日骚| 欧美精品少妇一区二区三区| 男人的天堂成人在线| 老**午夜毛片一区二区三区| 久久久中精品2020中文| 久久国产精品色婷婷| 欧美在线视频导航| 久久成人综合视频| 久久久久久电影| 久久久久亚洲综合| 免费观看一区| 欧美国产亚洲视频| 欧美日韩美女在线观看| 欧美日韩一视频区二区| 欧美日韩综合精品| 国产精品久久久对白| 国产日韩欧美黄色| 黄色资源网久久资源365| 伊人狠狠色丁香综合尤物| 亚洲福利视频一区二区| 亚洲精品美女91| 一道本一区二区| 亚洲在线国产日韩欧美| 欧美一区二区观看视频| 久久久久青草大香线综合精品| 久久天堂国产精品| 欧美高清视频www夜色资源网| 亚洲精品1区2区| 亚洲图片在线观看| 久久不见久久见免费视频1| 久久免费一区| 欧美日韩你懂的| 国产情人综合久久777777| 亚洲国产精品久久久久久女王| 99精品久久| 久久精品动漫| 亚洲国产欧美国产综合一区| 亚洲视频国产视频| 久久久精彩视频| 欧美日韩人人澡狠狠躁视频| 国产日产欧美精品| 日韩午夜激情电影| 久久精品视频亚洲| 亚洲精品一区中文| 久久成人综合网| 欧美日韩免费观看一区二区三区 | 美女主播视频一区| 欧美日韩在线视频一区| 很黄很黄激情成人| 在线中文字幕一区| 美女爽到呻吟久久久久| 国产精品99久久不卡二区| 久久精品视频导航| 国产精品久久久久久久久久ktv| 亚洲成人影音| 久久福利毛片| 99综合精品|