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!) ...
随机推荐
- fatal error C1047: The object or library file xxx was created with an older compiler than other objects
之前编译Cocos2DX时遇到过一次,这次又遇到了,记下解决方法,以防再来第三次. 这个错误是说链接的库或者文件是老版本编译器生成的,与当前编译器不符,比如这次用的预编译库是2015的,而我当前使用的 ...
- UI自动化处理文件上传
UI自动化处理文件上传 import win32guiimport win32con def set_uploader(self, file_path): sleep(2) self.file_pat ...
- CCNA 之 二 OSI七层模型
OSI网际互联 OSI的概念 英文全称Open System Interconnect 开放系统互联参数模型,是由ISO国际标准化组织 定义的.它是个灵活的.稳健的和可互操作的模型,并不是协议,使用来 ...
- ping局域网主机得到外网IP或另一网段IP
症状::两个笔记本连接到同一个路由器上, 一个ip是 192.168.1.100,主机名是Lenovo-A, 另一个是192.168.1.109,主机名是Lenovo-B 在Lenovo-A 上pin ...
- stl(set和pair)
D - 4 Gym - 100989D In this cafeteria, the N tables are all ordered in one line, where table number ...
- Manacher(最长回文串)
http://acm.hdu.edu.cn/showproblem.php?pid=3068 最长回文 Problem Description 给出一个只由小写英文字符a,b,c...y,z组成的字符 ...
- P5030 长脖子鹿放置
题目背景 众周所知,在西洋棋中,我们有城堡.骑士.皇后.主教和长脖子鹿. 题目描述 如图所示,西洋棋的"长脖子鹿",类似于中国象棋的马,但按照"目"字攻击,且没 ...
- 02 java内存模型
java内存模型 1.JVM内存区域 方法区:类信息.常量.static.JIT (信息共享) java堆:实例对象 GC (信息共享) OOM VM stack:JAVA方法在运行的内存模型 (OO ...
- C#设计模式:工厂模式
一,工厂模式 using System; using System.Collections.Generic; using System.Linq; using System.Text; using S ...
- Panabit的各种配置文件
Panabit的各种配置文件 1.启动配置文件路径:/etc/rc.local作用:这个文件里的内容是BSD启动后会自动执行的命令默认配置如下:fsck -y -t ufs /dev/ad0s2a & ...