cdoj 791 Frozen Rose-Heads
//本来想做白书上一题 结果发现又要二染色 又要dp的 想了两个小时没想通 然后做了个傻逼题安慰自己
解:不多说,就是递归到叶节点,然后回来的时候在解决子树和直接删边的代价中间取个最小值
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<string> using namespace std; const int MAXN=;
const int MAXINT=; int n,c;
vector <int> G[MAXN];
int cost[MAXN][MAXN]; int dfs(int now,int fa){
if (G[now].size()== && G[now][]==fa){
return MAXINT;
}
int tmp=;
for (int i=;i<(int)G[now].size();i++){
if (G[now][i]==fa) continue;
tmp=tmp+min(dfs(G[now][i],now),cost[now][G[now][i]]);
}
return tmp;
} int main(){
while (scanf("%d%d",&n,&c)==){
for (int i=;i<=n;i++) G[i].clear();
for (int i=;i<n-;i++){
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
cost[x][y]=z;
cost[y][x]=z;
G[x].push_back(y);
G[y].push_back(x);
}
printf("%d\n",dfs(c,-));
}
return ;
}
/*
3 1
2 1 5
1 3 4
7 7
7 6 10
7 5 10
6 4 1
6 3 1
5 2 1
5 1 2 4 1
1 2 1
2 3 1
2 4 1
*/
cdoj 791 Frozen Rose-Heads的更多相关文章
- UESTC_Frozen Rose-Heads CDOJ 791
The winter is coming and all the experts are warning that it will be the coldest one in the last hun ...
- 用rose画UML图(用例图,活动图)
用rose画UML图(用例图,活动图) 首先,安装rose2003,电脑从win8升到win10以后,发现win10并不支持rose2003的安装,换了rose2007以后,发现也不可以. 解决途径: ...
- 基于腾讯手Q样式规范Frozen UI
Frozen UI是一个开源的简单易用,轻量快捷的移动端UI框架.基于手Q样式规范,选取最常用的组件,做成公用离线包减少请求,升级方式友好,文档完善,目前全面应用在腾讯手Q增值业务中. css组件包括 ...
- IO is frozen on database xxx, No user action is required
最近遇到一起关于"I/O is frozen on database xxx. No user action is required. However, if I/O is not resu ...
- 关于refs/for/ 和refs/heads/
1. 这个不是git的规则,而是gerrit的规则, 2. Branches, remote-tracking branches, and tags等等都是对commite的引用(re ...
- 解决Rational Rose 中 没有 Data modeler 选项的问题
在 Rose 没有 Data modeler 选项的原因是没有将 Data modeler 这块功能勾选上. 解决方案: 菜单栏--Add-Ins--Add-Ins Manager-->找到 ...
- Rational Rose
Rational Rose简明实用教程 http://furzoom.com/rational-rose-course/ Unidirectional Association 单向关联 general ...
- 带领大家安装Rational rose
Rational rose下载地址:http://pan.baidu.com/s/1hqIIyJq?qq-pf-to=pcqq.c2c 下载好后,文件里有4个安装文档: 解压CD1和CD2到当前目录, ...
- UML基础与Rose建模实训教程
目 录 第1章 初识UML. 1 1.1 初识UML用例图... 1 1.2 初识UML类图... 3 第2章 Rational Rose工具... 6 2.1 安装与配置Rational Ro ...
随机推荐
- 定制样式插入到ueditor
AngularJs定制样式插入到ueditor中的问题总结 总结一下自己给编辑器定制样式的过程中所遇到的问题,主要是编辑器的二次开发接口,以及用angular定制样式,问题不少,终于在**的帮助下,完 ...
- keepalived 安装和配置
第一步:安装 yum -y install keepalived 第二步:配置 /etc/keepalived/keepalived.conf ! Configuration File for kee ...
- SQL Server 对象
第一项:重命名对象 execute sp_rename @objname='Nums',@newname ='Numbers',@objtype ='object'; go 这里要特别小心 @ne ...
- HTML5 Audio时代的MIDI音乐文件播放
大家都知道,HTML5 Audio标签能够支持wav, webm, mp3, ogg, acc等格式,但是有个很重要的音乐文件格式midi(扩展名mid)却在各大浏览器中都没有内置的支持,因为mid文 ...
- 十个JAVA程序员容易犯的错误
十个JAVA程序员容易犯的错误 1. Array 转 ArrayList 一般开发者喜欢用: List<String> list = Arrays.asList(arr); Arrays. ...
- IOS开发之——获取屏幕的尺寸及各模拟器代表的型号
获取屏幕尺寸 [[[UIScreen mainScreen] currentMode].size.width]; [[[UIScreen mainScreen] currentMode].size.h ...
- HDU2594——Simpsons’ Hidden Talents
Problem Description Homer: Marge, I just figured out a way to discover some of the talents we weren’ ...
- 链接脚本之LMA VMA解释
链接脚本中的LMA和VMA是什么意思.这个问题纠结了一段时间,今天在看<ARM体系结构与编程>时,豁然开朗,写下自己的认识.分享例如以下: LMA:载入地址 位于存储器中的地址 LOAD ...
- flexigrid 修改json格式
1.修改默认的json格式为key:value 修改前 rows: [{id:'ZW',cell:['ZW','ZIMBABWE','Zimbabwe','ZWE','716']},{id:'ZW', ...
- 安装Discuz!论坛时提示“mysqli_connect() 不支持 advice_mysqli_connect”
安装Discuz!论坛时提示“不支持Mysql数据库,无法安装论坛”的解决方法1,在系统的 system32(C:\windows\system32)目录下缺少libmysql.dll文件,解决方法是 ...