//本来想做白书上一题 结果发现又要二染色 又要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的更多相关文章

  1. 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 ...

  2. 用rose画UML图(用例图,活动图)

    用rose画UML图(用例图,活动图) 首先,安装rose2003,电脑从win8升到win10以后,发现win10并不支持rose2003的安装,换了rose2007以后,发现也不可以. 解决途径: ...

  3. 基于腾讯手Q样式规范Frozen UI

    Frozen UI是一个开源的简单易用,轻量快捷的移动端UI框架.基于手Q样式规范,选取最常用的组件,做成公用离线包减少请求,升级方式友好,文档完善,目前全面应用在腾讯手Q增值业务中. css组件包括 ...

  4. 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 ...

  5. 关于refs/for/ 和refs/heads/

    1.     这个不是git的规则,而是gerrit的规则, 2.     Branches, remote-tracking branches, and tags等等都是对commite的引用(re ...

  6. 解决Rational Rose 中 没有 Data modeler 选项的问题

    在  Rose  没有 Data modeler 选项的原因是没有将 Data modeler 这块功能勾选上. 解决方案: 菜单栏--Add-Ins--Add-Ins Manager-->找到 ...

  7. Rational Rose

    Rational Rose简明实用教程 http://furzoom.com/rational-rose-course/ Unidirectional Association 单向关联 general ...

  8. 带领大家安装Rational rose

    Rational rose下载地址:http://pan.baidu.com/s/1hqIIyJq?qq-pf-to=pcqq.c2c 下载好后,文件里有4个安装文档: 解压CD1和CD2到当前目录, ...

  9. UML基础与Rose建模实训教程

    目  录 第1章  初识UML. 1 1.1 初识UML用例图... 1 1.2 初识UML类图... 3 第2章  Rational Rose工具... 6 2.1 安装与配置Rational Ro ...

随机推荐

  1. Ice_cream's world I--hdu2120

    Ice_cream's world I Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  2. gl.TexSubImage2D 使用遇到图片翻转的问题

    这2天在用gl.TexSubImage2D把几张小图转拼接成大图,如果在渲染物体之前拼接好就没有问题,但在开始渲染物体后拼接就会有问题.后来我做了2件事情来找原因, 1. 用拼好的图来画一个正方形,大 ...

  3. 浅谈38K红外发射接受编码

    之前做接触过一次红外遥控器,现在有空想用简单的话来聊一聊,下面有错误的地方欢迎改正指出:1:红外的概念不聊,那是一种物理存在.以下聊38K红外发射接收,主要讲可编程的红外编码.2:红外遥控 红外遥控首 ...

  4. Android开发之ExpandableListView扩展(BaseExpandableListAdapter的使用)(完整版)

    Android开发之ExpandableListView扩展(BaseExpandableListAdapter的使用)(完整版)

  5. linux上应用随机启动

    这是个go项目,其他的可以参考. 首先要有个脚本比如demo #!/bin/bash # # etcd This shell script takes care of starting and sto ...

  6. UIView添加事件

    UIView *loadView = [[UIControl alloc]initWithFrame:CGRectMake(0,0,320,480)]; loadView.backgroundColo ...

  7. 如何将Oracle安装为Linux服务

    方法一:使用oracle自带的启动和关闭脚本 1. oracle用户修改/etc/oratab 文件: $ vi /etc/oratab orcl:/oracle/app/product/10.2.0 ...

  8. uva156 By sixleaves

    1 #include <iostream> 2 #include <string> 3 #include <algorithm> 4 #include <ma ...

  9. bat命令学习笔记

    1.一般在开始声明 setlocal enabledelayedexpansion 设置本地为延迟扩展.其实也就是:延迟变量,全称延迟环境变量扩展,使得批处理能够感知到变量的动态变化,在运行过程中给变 ...

  10. Object-C自定义对象NSLog输入信息

    http://blog.cnrainbird.com/index.php/2012/07/19/object-c_zi_ding_yi_dui_xiang_nslog_shu_ru_you_yong_ ...