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 ...
随机推荐
- HDU 4121 Xiangqi
模拟吧,算是... 被这个题wa到哭,真是什么都不想说了...上代码 #include <iostream> #include <cstring> using namespac ...
- CodeForces 190A Vasya and the Bus
本题是比较简单的,有几个坑要注意一下: 1.n==0&&m!=0 时输出 "Impossible" : 2.n==0&&m==0 时输出 ”0 0 ...
- PHP中的错误处理
程序只要在运行,就免不了会出现错误!或早或晚,只是时间问题罢了. 错误很常见,比如Notice,Warning等等.此时一般使用set_error_handler来处理: <?php set_e ...
- JIT和程序的首次执行
由于C#源代码经过编译器编译生成的是IL代码,而IL是与CPU无关的机器语言.因此当程序运行于特定的CPU时,首先必须将IL转换成本地CPU指令,这正是JIT(Just-In-Time)编译器的任务. ...
- linux之SQL语句简明教程---CONCATENATE
有的时候,我们有需要将由不同栏位获得的资料串连在一起.每一种资料库都有提供方法来达到这个目的: MySQL: CONCAT( ) Oracle: CONCAT( ), || SQL Server: + ...
- 全国计算机等级考试二级教程-C语言程序设计_第2章_C程序设计的初步知识
正负号与被除数一致. 3 % (-5) == 3 (-3) % 5 == -3 不用求余运算符,求出余数. int x, y; 答:x - x / y * y; const int i = 10; c ...
- CF 444A(DZY Loves Physics-低密度脂蛋白诱导子图)
A. DZY Loves Physics time limit per test 1 second memory limit per test 256 megabytes input standard ...
- cocos2d-x 3.0游戏实例学习笔记《卡牌塔防》第七步---英雄要升级&属性--解析csv配置文件
/* 说明: **1.本次游戏实例是<cocos2d-x游戏开发之旅>上的最后一个游戏,这里用3.0重写并做下笔记 **2.我也问过木头本人啦.他说:随便写,第一别全然照搬代码:第二能够说 ...
- ORACLE表空间管理方式segment和extent
A permanent tablespace contains persistent schema objects. Objects in permanent tablespaces are stor ...
- ubuntu高版本环境变量问题
在ubuntu较高的版本(博主使用的是14.10)下,可以在/etc/environment中配置环境变量,这个环境变量可能会覆盖用户~/.bashrc中配置的环境变量,这个应该引起注意.