【题意】

  输入三元组(X,Y,C),有向图,定根0,输出MDST。

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 calls are 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
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
Sample Output
Case #1: 10
Case #2: Possums!
Case #3: 40
Case #4: 130

【分析】

  裸的MDST。

  哇,自己打一下真是各种bug orz。。。

 1 #include<cstdio>
 2 #include<cstdlib>
 3 #include<cstring>
 4 #include<iostream>
 5 #include<algorithm>
 6 #include<queue>
 7 using namespace std;
 8 #define Maxn 1010
 9 #define Maxm 40010
10 #define INF 0xfffffff
11
12 struct node
13 {
14     int x,y,c;
15 }t[Maxm];
16
17 int in[Maxn],vis[Maxn],id[Maxn],pre[Maxn];
18
19 int n,m,rt;
20
21 int MDST()
22 {
23     int ans=0;
24     rt=1;
25     while(1)
26     {
27         for(int i=1;i<=n;i++) in[i]=INF;
28         for(int i=1;i<=m;i++)
29         {
30             int x=t[i].x,y=t[i].y;
31             if(t[i].c<in[y]&&x!=y)
32             {
33                 in[y]=t[i].c;
34                 pre[y]=x;
35             }
36         }
37         for(int i=1;i<=n;i++) if(i!=rt&&in[i]==INF) return -1;
38         memset(vis,-1,sizeof(vis));
39         memset(id,-1,sizeof(id));
40         int cnt=0;
41         for(int i=1;i<=n;i++) if(i!=rt)
42         {
43             ans+=in[i];
44             int now=i;
45             while(vis[now]!=i&&id[now]==-1&&now!=rt)
46             {
47                 vis[now]=i;
48                 now=pre[now];
49             }
50             if(now!=rt&&id[now]==-1)
51             {
52                 cnt++;
53                 for(int j=pre[now];j!=now;j=pre[j])
54                     id[j]=cnt;
55                 id[now]=cnt;
56             }
57         }
58         if(cnt==0) break;
59         for(int i=1;i<=n;i++) if(id[i]==-1) id[i]=++cnt;
60         for(int i=1;i<=m;i++)
61         {
62             int x=t[i].x,y=t[i].y;
63             t[i].x=id[x];t[i].y=id[y];
64             if(t[i].x!=t[i].y) t[i].c-=in[y];
65         }
66         rt=id[rt];
67         n=cnt;
68
69     }
70     return ans;
71 }
72
73 int main()
74 {
75     int T,kase=0;
76     scanf("%d",&T);
77     while(T--)
78     {
79         scanf("%d%d",&n,&m);
80         for(int i=1;i<=m;i++)
81         {
82             scanf("%d%d%d",&t[i].x,&t[i].y,&t[i].c);
83             t[i].x++;t[i].y++;
84         }
85         printf("Case #%d: ",++kase);
86         int x=MDST();
87         if(x==-1) printf("Possums!\n");
88         else printf("%d\n",x);
89     }
90     return 0;
91 }

View Code

2016-11-01 14:42:51

转载于:https://www.cnblogs.com/Konjakmoyu/p/6019370.html

【UVA 11183】 Teen Girl Squad (定根MDST)相关推荐

  1. uva 11183 Teen Girl Squad

    题意: 有一个女孩,需要打电话让所有的人知道一个消息,消息可以被每一个知道消息的人传递. 打电话的关系是单向的,每一次电话需要一定的花费. 求出打电话最少的花费或者判断不可能让所有人知道消息. 思路: ...

  2. UVA11183 Teen Girl Squad —— 最小树形图

    题目链接:https://vjudge.net/problem/UVA-11183 You are part of a group of n teenage girls armed with cell ...

  3. kuangbin带你飞专题合集

    题目列表 [kuangbin带你飞]专题一 简单搜索 [kuangbin带你飞]专题二 搜索进阶 [kuangbin带你飞]专题三 Dancing Links [kuangbin带你飞]专题四 最短路 ...

  4. 算法学习经典例题整理

    陆续会对本篇博客进行更新! 搜索:https://vjudge.net/contest/292597 区间DP:https://vjudge.net/contest/293892 树状背包:https ...

  5. kuangbin带你飞 专题1-23 题单

    kuangbin大神,对于打过ACM比赛的ACMer,无人不知无人不晓. 在此,附上vjudge平台上一位大神整理的[kuangbin带你飞]专题目录链接. [kuangbin带你飞专题目录1-23] ...

  6. 老鱼的-kuangbin专题题解

    kuangbin专题问题一览 专题一 简单搜索 POJ 1321 棋盘问题 POJ 2251 Dungeon Master POJ 3278 Catch That Cow POJ 3279 Flipt ...

  7. [kuangbin]各种各样的题单

    [kuangbin]各种各样的题单 专题1 简单搜索 POJ 1321 POJ 2251 POJ 3278 POJ 3279 POJ 1426 POJ 3126 POJ 3087 POJ 3414 F ...

  8. uva live 7635 National Bomb Defusing Squad

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  9. [搜索]UVa 129 困难的串

    题意:将一个包含两个相邻的重复子串的子串,称为"容易的串",其他为"困难的串". 输入正整数n和l,输出由前l个字符组成的,字典序第n小的困难的串. 输入样例: ...

最新文章

  1. SpringBoot (二) :全局异常处理设置
  2. 用strings命令输出文件中的可打印字符
  3. List遍历过程中删除数据
  4. Servlet3.0下配置Servlet
  5. 搜狐html源码,使用css和html模仿搜狐页面
  6. sql 获取数据库字段信息_使用DBATools获取SQL数据库详细信息
  7. 【C++】C++继承和派生类、虚基类
  8. Linux 克隆虚拟机引起的“Device eth0 does not seem to be present, delaying initialization”
  9. SaaS到底是什么,如何做?——这份我亲手整理的笔记您收好了!
  10. hist seg, find peaks, tps, pava单调拟合, isotonic-regression,REGULARIZED DISCRETE OPTIMAL TRANSPORT
  11. C语言·三角形已知三边求面积题
  12. 有关“iusb3mon.exe已停止工作”的解决方法与我解决这个问题的坑爹经历。
  13. python calu_Python中*args,**kwargs的使用
  14. 通过自定义android键盘实现车牌号输入法
  15. C++黑客攻击系统-功能菜单
  16. 后来我放弃了Obsidian手机端,改用Flomo | Obsidian实践
  17. 2012美国大选献金项目数据分析
  18. 滚珠丝杠与普通丝杠区别
  19. [新增EA028高压注射器]24套UML+EA和StarUML的建模示范视频-全程字幕(2022.7.4更新)
  20. Blender图解教程:马里奥食人花三部曲(一)建模和贴图(附模型下载)

热门文章

  1. html css学习笔记~ 基础知识和页面显示的四个区域内容及display:flex 等常用的一些命令(手画)
  2. 中国机械对流烘箱行业市场供需与战略研究报告
  3. 【Planning】R3 PTF and firm mapped with APO
  4. 详解Tomcat配置及使用
  5. 【C/C++面试必备】声明和定义的区别
  6. 用结构体练习 考生信息录入
  7. node js 运行服务器,node.js – NodeJS服务器如何运行
  8. 牛客寒假基础集训营 | Day1 D题—hanayo和米饭
  9. Python中的repr()函数与 ‘!r‘的作用
  10. 360安全杀毒软件扫描计算机病毒吗,360杀毒软件全盘扫描杀毒教程