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!) ...
随机推荐
- Vue过渡:用Velocity实现JavaScript钩子
Velocity is an animation engine with a similar API to jQuery's $.animate(). It has no dependencies, ...
- 微信、QQ、新浪微博等第三方登录,你想知道的都在这了(上) 微信、QQ、新浪微博等第三方登录,你想知道的都在这了(下)
微信.QQ.新浪微博等第三方登录,你想知道的都在这了(上):https://www.jianshu.com/p/133d84042483 微信.QQ.新浪微博等第三方登录,你想知道的都在这了(下):h ...
- 【五一qbxt】day5 图论
图论 学好图论的基础: 必须意识到图论hendanteng xuehuifangqi(雾 图 G = (V,E) 一般来说,图的存储难度主要在记录边的信息 无向图的存储中,只需要将一条无向边拆成两条即 ...
- 洛谷 P3368 【模板】树状数组 2(区间加,单点查询)
题目链接 https://www.luogu.org/problemnew/show/P3368 树状数组 最基础的用法:https://www.cnblogs.com/yinyuqin/p/1096 ...
- P1613跑路
题目描述 小A的工作不仅繁琐,更有苛刻的规定,要求小A每天早上在6:00之前到达公司,否则这个月工资清零.可是小A偏偏又有赖床的坏毛病.于是为了保住自己的工资,小A买了一个十分牛B的空间跑路器,每秒钟 ...
- Link-Cut-Tree学习(LCT)
Link-Cut-Tree学习(LCT) 真不敢想象我居然学会LCT了,但是我仍然不想写一篇博客来梳理 我怕一梳理自己又不懂了 但是作为一名朴实沉毅的cjoier,我决定小小的梳理一下,并不打算很精致 ...
- python常用模块---collections、time、random、os、sys、序列号模块
collections模块 在内置数据类型(dict.list.set.tuple)的基础上,collections模块还提供了几个额外的数据类型:Counter.deque.defaultdict. ...
- Python自学第二天学习之《字符串与数字》
一.基本数据类型: 数字:int类型,不可变类型 格式 : a=10 1.其他类型转换成int型 : b=“123” c=int(b) #转换类型 print(c)----- 123 print(ty ...
- 分析abex'crackme#2
文件地址:https://www.wocloud.com.cn/webclient/share/sindex.action?id=i9K_Br6TgE4gbyGIlYkffWKcRy5TUdZ8U6_ ...
- 根据select选择来控div是否显示,默认这个div是隐藏的,
<!DOCTYPE html><html><head lang="cn"><title>Insert title here</ ...