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!) ...
随机推荐
- charles模拟弱网情况
网络主要需要注意什么场景: 弱网功能测试 无网状态测试 网络切换测试 用户体验关注 下面我们使用charles测试弱网,针对不同网络下的测试 打开charles(抓包软件)
- SpringBoot实现上传下载(二)
这篇写下载. **1.实现思路** 上一篇的数据库设计中,我们有一个字段始终没有用到fileName,这是用来给Layer对象存储文件名的,以此来完成文件与对象的对应,  最开始没想到数学题,把所有部分分都说一遍吧: 35分:纯暴力O(M^4)枚举,对于每一组a,b,c,d验证其是否合法. 60分: ...
- Codeforces - 1195D1 - Submarine in the Rybinsk Sea (easy edition) - 水题
https://codeforc.es/contest/1195/problem/D1 给\(n\)个等长的十进制数串,定义操作\(f(x,y)\)的结果是"从\(y\)的末尾开始一个一个交 ...
- python学习三十五天函数递归的用法
python函数递归就是自己调用自己,无限循环,但是python限制了调用的次数1000次,就会终止,递归用在栏目分类,采集程序比较多,下面简单说函数递归用法和实例 1,函数递归用法 def func ...
- C#设计模式:策略者模式(Stragety Pattern)
一,什么是策略模式? 1,针对同一命令或行为,不同的策略做不同的动作. 2,比如针对一组算法,将每个算法封装到具有公共接口的独立的类中,从而使它们可以相互替换.策略模式使得算法可以在不影响到客户端的情 ...
- axios 如何获取下载文件的进度条
exportFun(){ let _that = this const instance = this.axios.create({ onDownl ...
- JS中 [] == ![]结果为true,而 {} == !{}却为false
为什么? 先转换再比较 (==) 仅比较而不转换 (===) ==转换规则? ==比较运算符会先转换操作数(强制转换),然后再进行比较 ①如果有一个操作数是布尔值,则在比较相等性之前 ...
- Intellij IDEA插件
1.lombok 通过注解的形式生成GET/SET等方法 2.FindBugs-IDEA 检测代码中可能的bug及不规范的位置 3.Maven Helper 一键查看maven依赖,查看冲突的依赖,一 ...
- 开源安全:PE分析
https://github.com/JusticeRage/Manalyze.git https://github.com/JusticeRage/Manalyze https://www.free ...