POJ 3164 Command Network & amp; ultraviolet A 11183 Teen Girl Squad minimum tree structure

Source: Internet
Author: User
Tags cmath

POJ 3164 Command Network & ultraviolet A 11183 Teen Girl Squad minimum tree structure

Minimum treasure: To put it simply, find the minimum treasure of the G0 of an image, and first find the shortest arc set E0. If E0 does not exist, the shortest tree of fig G0 does not exist. If an exists and does not include an undirected ring, E0 is all edges in T0. If E0 exists and contains a directed ring, the directed ring is reduced to a point u, and G1 is formed. The shortest tree of G1 continues until Gi, if the graph Gi does not have a minimum tree segment, then there is no minimum tree segment in the graph G0. If the Gi has a minimum tree segment Ti. the T0 value is displayed layer by layer.

Ultraviolet A 11183 Teen Girl Squad
Input: Standard Input
Output: Standard Output

-3 spring rolls please.
-MSG 'd !!
-Oh! My stomach lining!
Strong Bad
You are part of a group of n teenage girls armed with cellphones. you have some news you want to tell everyone in the group. the problem is that no two of you are in the same room, and you must communicate using only cellphones. what's worse is that due to excessive usage, your parents have refused to pay your cellphone bills, so you must distribute the news by calling each other in the cheapest possible way. you will call several of your friends, they will call some of their friends, and so on until everyone in the group hears the news.
Each of you is using a different phone service provider, and you know the price of girl A calling girl B for all possible A and B. not all of your friends like each other, and some of them will never call people they don't like. your job is to find the cheapest possible sequence of callso that the news spreads from you to all n-1 other members of the group.
Input
The first line of input gives the number of cases, N (N <150 ). N test cases follow. each one starts with two lines containing n (0 <= n <= 1000) and m (0 <= m <= 40,000 ). girls are numbered from 0 to n-1, and you are girl 0. the next m lines will each contain 3 integers, u, v and w, meaning that a call from girl u to girl v costs w cents (0 <= w <= 1000 ). no other callare possible because of grudges, rivalries and because they are, like, lame. the input file size is around 1200 KB.

Output
For each test case, output one line containing "Case # x:" followed by the cost of the cheapest method of distributing the news. If there is no solution, print "Possums !" Instead.

Sample Input Output for Sample Input
4
2
1
0 1 10
2
1
1 0 10
4
4
0 1 10
0 2 10
1 3 20
2 3 30
4
4
0 1 10
1 2 20
2 0 30
2 3 100
Case #1: 10
Case #2: Possums!
Case #3: 40
Case #4: 130

#include
  
   #include#include
   
    #include
    
     #include
     
      using namespace std;const int maxn=1010;const int INF = 0x3f3f3f3f;const int maxm =40010;struct Edge{    int u,v,cost;}edge[maxm];int pre[maxn],id[maxn],vis[maxn],in[maxn];int zhuliu(int root,int n,int m,Edge edge[]){    int u,v;    int res=0;    while(1)    {        for(int i=0;i<n;i++) in[i]="INF;" for(int="" i="0;i
      
     
    
   
  

After the previous question has met this question, I think about it very much. Let's practice the code yourself!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.