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 ...
随机推荐
- UVA 1599 Ideal Path (HDU 3760)
两次bfs: 第一次bfs逆向搜索,得到每个点到终点的最短距离,找出最短路:第二次bfs根据最短距离可以选择满足条件的最短路. 注意!碰到这种很大数据量的题目一定要记得用scanf,printf 输入 ...
- SQL中 and or优先级问题(转)
刚刚在项目中遇到这样一个问题,SQL语句如下: select * from LOAN_BACK_LIBRARY where LIBRARY_ID=1 or LIB_ID=1 and STATUS=3 ...
- 在IE浏览器中iframe跨域访问cookie/session丢失的解决办法
单点登录需要在需要进入的子系统B中添加一个类,用于接收A系统传过来的参数: @Action(value = "outerLogin", results = { @Result(na ...
- 常用的IO流
常用的IO流 •根据处理数据类型的不同分为:字节流和字符流 •根据数据流向不同分为:输入流和输出流 字节流:字节流以字节(8bit)为单位,能处理所有类型的数据(如图片.avi等). 字节输入流:In ...
- poj1581
A Contesting Decision Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2519 Accepted: ...
- C#调用HTTP接口
string url = "http://www.***.com?id=123&username=test&userpwd=*****"; WebRequest w ...
- android笔记1——开发环境的搭建
Long Long ago...已经成为了历史,我还是要说出一个真相:早年前,那时候,android还不被大众所认知的时候,当然开发人员也没不像如今那样趋于饱和状态.一位大牛前辈,也是我的学长,那时候 ...
- 通过Jetty搭建一个简单的Servlet运行环境
最近在做一些简单的Servlet开发的时候,感觉每次调试的时候都要发布到tomcat上很麻烦,把程序共享给同事也很麻烦,需要帮他设置本地的tomcat环境. 在网上找了找其他的Servlet运行环境, ...
- optimizer for eclipse--Eclipse优化,让你的Eclipse快来飞!
官方网站:http://zeroturnaround.com/free/optimizer-for-eclipse/ infoq网址:http://www.infoq.com/cn/news/2015 ...
- animate CSS动画程序接口(仅Chrome可用)
jQuery中很早就提供了animate方法,使用它可以很方便地实现一些简单动画效果.后来CSS3中也提供了animation用于动画效果制作,但CSS本身的可操作性太差,所以用起来并不方便.现在最新 ...