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!) ...
随机推荐
- html基础与表格的理解·
1.静态网页与动态网页的区别:是否访问数据库 2.超文本:超文本是指超出文本的范围,可以插入声音视频,表格图片等 3.标记语言与网页结构:标记语言就是标签,网页结构包含<html>< ...
- linux新建用户并修改提示符
1 新建用户 # useradd –d /home/ap/testapp -m testapp 此命令创建了一个用户testapp ,其中-d和-m选项用来为登录名testapp 产生一个主目录/ho ...
- 经常用到的meta标签的整理
1.设置页面关键词<meta name="keywords" content="输入具体的关键词">2.设置页面的描述<meta name=& ...
- python web自动化测试框架搭建(功能&接口)——测试用例执行和结果收集
由于unittest框架中结果收集在不同文件中,所以此处重写结果收集方法,加入执行时间,失败信息,失败截图等 TestRunner.py # coding=utf-8 import sys impor ...
- 第1 章 mysql数据库之简单的DDL和DML sql语句
一.SQL 介绍 1.什么是sql? SQL,英文全称(Structured Query Language),中文是结构化查询语言,它是一种对关系数据库中数据进行定义和操作的语言方法,是大多数关系数据 ...
- Fitness初接触
http://www.fitnesse.org/FitNesseDownload 1. Click on the most recent fitnesse-standalone.jar file an ...
- python面试题之Python 的特点和优点是什么
Python 可以作为编程的入门语言,因为他具备以下特质: 1. 解释性 2. 动态特性 3. 面向对象 4. 语法简洁 5. 开源 6. 丰富的社区资源 7 库丰富 文章转载自Python黑洞网
- MIT 6.824学习笔记2 RPC/Thread
本节内容:Lect 2 RPC and Threads 线程:Threads allow one program to (logically) execute many things at onc ...
- Python之文件路径名的操作
使用 os.path 模块中的函数来操作路径名 import os # 获取当前文件路径 path=os.path.abspath(__file__) # 获取绝对路径 /home/zzy/Pycha ...
- vue 页面切换从右侧切入效果
1.将切换的页面用transition包裹 <div class="index-content"> <transition> <router-view ...