$P3931 SAC E一道难题 Tree$
#include <bits/stdc++.h>
#define rep(i,j,n) for(register int i=j;i<=n;i++)
#define Rep(i,j,n) for(register int i=j;i>=n;i--)
#define low(x) x&(-x)
using namespace std ;
typedef long long LL ;
const int inf = INT_MAX >> 1 ;
inline LL In() { LL res(0) , f(1) ; register char c ;
#define gc c = getchar()
while(isspace(gc)) ; c == '-' ? f = - 1 , gc : 0 ;
while(res = (res << 1) + (res << 3) + (c & 15) , isdigit(gc)) ;
return res * f ;
#undef gc
}
int n , s ;
const int N = 100000 + 5 ;
const int M = N << 1 ;
int nxt[M] ;
int to[M] ;
int head[N] ;
LL dis[M] ;
int tot(1) ;
inline void Add(int u, int v, LL w) {
nxt[++ tot] = head[u] , head[u] = tot , dis[tot] = w , to[tot] = v ;
}
inline LL Dfs(int x,int y) {
LL ans = 0 ;
bool ck = 0 ;
for(register int i = head[x] ; i ; i = nxt[i]) {
if(to[i] == y) continue ;
ans += min(Dfs(to[i] , x) , dis[i]) , ck = 1 ;
}
if(ck == 0) return LLONG_MAX ;
return ans ;
}
inline void Ot() {
n = In() - 1 , s = In() ;
rep(i,1,n) {
int u = In() , v = In() ;
LL w = In() ;
Add(u,v,w) , Add(v,u,w) ;
}
cout << Dfs(s , s) << endl ;
}
signed main() {
return Ot() , 0 ;
}
随机推荐
- Python机器学习入门(1)之导学+无监督学习
Python Scikit-learn *一组简单有效的工具集 *依赖Python的NumPy,SciPy和matplotlib库 *开源 可复用 sklearn库的安装 DOS窗口中输入 pip i ...
- 第十二节:Web爬虫之MongoDB数据库安装与数据存储
MongoDB是一个基于分布式文件存储的数据库.由C++语言编写.旨在为WEB应用提供可扩展的高性能数据存储解决方案. MongoDB是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功 ...
- Spring AOP学习(六)
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- Android BottomSheet:以选取图片为例(2)
Android BottomSheet:以选取图片为例(2) 附录文章5简单介绍了常见的分享面板在BottomSheet中的具体应用.本文再以常见的选取图片为例写一个例子. 布局文件: < ...
- Hadoop2.0之YARN
YARN(Yet Another Resource Negotiator)是Hadoop2.0集群中负责资源管理和调度以及监控运行在它上面的各种应用,是hadoop2.0中的核心,它类似于一个分布式操 ...
- kfk: async disk IO深度解析
http://www.itpub.net/thread-1724044-1-1.html
- strace oracle
http://www.itpub.net/thread-1865593-1-1.html
- 多Tabs的横向滚动插件(支持Zepto和jQuery)
一. 效果图 二. 功能介绍 1. 支持横向移动 2. 支持点击Tab后该Tab居中 3. 拉到最左边和最右边后依然可以拉动,只是tabs的移动距离变小. 三. 使用说明 1. 在你的html中添加T ...
- VS2012调试执行,网页打不开
360修复漏洞篇 TODO 修复了漏洞.vs2012在firefox和ie中都打不开 解决思路:360漏洞修复→已安装漏洞→卸载刚刚安装的漏洞 就可以解决 忽略漏洞 正常打开.
- 创业公司十分钟简单搭建GIT私有库
欢迎关注老码农的微信公共账号,与CSDN博客同步 一.背景 小公司.协同开发的人不多,建gitlab比較麻烦,仅仅须要在Server端建立一个简单的git共享库就OK. 二.建立仓库 Server端: ...