Eternal Victory
题意:给出n个点,再给出n-1条路,想一口气从1走完n个点的最小距离。
思路:好像它不构成环!md没看清题目,所以说每次遍历完全部的点后,最短的路就是每条边的距离*2减去最长路的距离。
所以简单的dfs求最长路。
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<cstdio>
#include<cmath>
#define ll long long
using namespace std;
struct point
{
int x;
int y;
};
vector<point> v[];
int n;
int maxd;
void dfs(int x,int y,int d)
{
if(d>maxd)
maxd=d;
for(int i=;i<v[x].size();i++)
{
int nextt=v[x][i].x;
if(nextt!=y)
{
dfs(nextt,x,d+v[x][i].y);
}
}
}
int main()
{
scanf("%d",&n);
ll sum=;
maxd=;
for(int i=;i<=n-;i++)
{
int a;
point u;
scanf("%d%d%d",&a,&u.x,&u.y);
a--;
u.x--;
sum+=(ll)u.y;
v[a].push_back(u);
swap(a,u.x);
v[a].push_back(u);
}
sum*=;
dfs(,-,);
printf("%lld\n",sum-maxd);
}
Eternal Victory的更多相关文章
- D. Eternal Victory(dfs + 思维)
D. Eternal Victory time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 【CF61D】Eternal Victory
题目大意:给定一棵 N 个节点的树,求从 1 号节点(根节点)出发,任意节点结束,且至少经过每个节点一次的最短路径是多少. 题解:首先考虑最终要回到根节点的情况,可以发现最短路径长度一定等于该树边权的 ...
- Codeforces Beta Round #57 (Div. 2) A,B,C,D,E
A. Ultra-Fast Mathematician time limit per test 2 seconds memory limit per test 256 megabytes input ...
- ZOJ3741 状压DP Eternal Reality
E - Eternal Reality Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu S ...
- ZOJ 3741 Eternal Reality
Eternal Reality Time Limit: 2 Seconds Memory Limit: 65536 KB In ...
- 关于ehcache缓存中eternal及timeToLiveSeconds和timeToIdleSeconds的说明
今天发现开发项目启动时有警告提示:cache 'xx' is set to eternal but also has TTL/TTI set,发现是ehcache缓存设置冲突 所以决定在此mark一下 ...
- 2017ACM暑期多校联合训练 - Team 8 1006 HDU 6138 Fleet of the Eternal Throne (字符串处理 AC自动机)
题目链接 Problem Description The Eternal Fleet was built many centuries ago before the time of Valkorion ...
- codeforces 868B The Eternal Immortality【暴力+trick】
B. The Eternal Immortality time limit per test 1 second memory limit per test 256 megabytes input st ...
- Codeforces Round #439 (Div. 2) B. The Eternal Immortality
B. The Eternal Immortality 题目链接http://codeforces.com/contest/869/problem/B 解题心得:题意就是给出a,b,问(a!)/(b!) ...
随机推荐
- 《图解设计模式》读书笔记4-1 Bridge模式
目录 概念 代码 角色 类图 想法 概念 Bridge模式即桥接模式.顾名思义,这个模式的作用是将类的功能层次结构和类的实现层次结构连接起来. 功能层次结构 Something -SomethingG ...
- 使用eclipse制作war包方法 web项目打包到tomcat
打开eclipse在左侧右击项目名选择“Export” 在导出画面点击 “Web”->“WAR file”点击“Next” 点击“Browse…”选择文件的导出位置,Target run ...
- 第 11 章 python线程与多线程
一.什么是线程 在传统操作系统中,每个进程有一个地址空间,而且默认就有一个控制线程. 进程只是用来把资源集中到一起(进程只是一个资源单位,或者说资源集合),而线程才是cpu上的执行单位. 多线程(即多 ...
- 【转载】Spring boot学习记录(三)-启动原理解析
前言:本系列文章非本人原创,转自:http://tengj.top/2017/04/24/springboot0/ 正文 我们开发任何一个Spring Boot项目,都会用到如下的启动类 @Sprin ...
- C#清空StringBuilder的三种方法
1.Remove例: StringBuilder val = new StringBuilder(); val.Append("...."); val.Remove(0,val.L ...
- java.lang.NumberFormatException: For input string: "title"异常
java.lang.NumberFormatException: For input string: "title" at java.lang.NumberFormatExcept ...
- 《JAVA设计模式》之装饰模式(Decorator)
在阎宏博士的<JAVA与模式>一书中开头是这样描述装饰(Decorator)模式的: 装饰模式又名包装(Wrapper)模式.装饰模式以对客户端透明的方式扩展对象的功能,是继承关系的一个替 ...
- CentOS 安装开发工具包
这里使用组安装包,一次性安装所有开发者工具. 1.查看有那些组安装包可用. [root@bogon ~]# yum grouplist | more 2.搜索一下有哪些和 Development 有关 ...
- python学习三十五天函数递归的用法
python函数递归就是自己调用自己,无限循环,但是python限制了调用的次数1000次,就会终止,递归用在栏目分类,采集程序比较多,下面简单说函数递归用法和实例 1,函数递归用法 def func ...
- python学习三十四天函数高阶函数定义及用法
python函数高阶函数是把函数当成一个变量,传递给函数作为参数,或者函数的返回值里面有函数,都称为高阶函数, 1,把函数作为参数传递 def dac(x,y): return x+y def tes ...