problem

#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 ;
}

随机推荐

  1. Linux之iptables(五、firewall命令及配置)

    firewalld服务 firewalld是CentOS 7.0新推出的管理netfilter的工具 firewalld是配置和监控防火墙规则的系统守护进程.可以实现iptables,ip6table ...

  2. 【Codeforces 364A】Matrix

    [链接] 我是链接,点我呀:) [题意] 让你求出b[i][j]=s[i]*s[j]规则构成的矩阵 的所有子矩阵中子矩阵的和为a的子矩阵的个数 [题解] (x,y,z,t) 会发现它的和就是sum(x ...

  3. 爬虫——使用ItemLoader维护item

    在item的Filed()中设置参数函数,可以用来预处理item字段的数据,另一方面也方便程序代码的管理和重用 item中 from scrapy.loader.processors import M ...

  4. [bzoj2440]完全平方数[中山市选2011][莫比乌斯函数][线性筛][二分答案]

    题意:求第k个分解质因子后质因子次数均为一的数,即求第k个无平方因子数. 题解: 首先二分答案mid,那么现在就是要求出mid以内的无平方因子数的个数. 其次枚举$\sqrt{mid}$内的所有质数, ...

  5. tyvj1117 拯救ice-cream

      背景 天好热……Tina顶着那炎炎的烈日,向Ice-cream home走去……可是……停电了……冰淇淋们躺在Ice-cream home的冰柜里,慢慢地……慢慢地……融化…………你说,她能赶在冰 ...

  6. spring-boot-starter-actuator(健康监控)配置和使用

    在生产环境中,需要实时或定期监控服务的可用性.Spring Boot的actuator(健康监控)功能提供了很多监控所需的接口,可以对应用系统进行配置查看.相关功能统计等. 集成: <depen ...

  7. 时间插件,js格式化,js某月天数,js某月最后一天日期

    //时间格式化 Date.prototype.format = function(fmt) { var o = { "M+": this.getMonth() + 1, //月份 ...

  8. 淘宝手机rem的如何使用

    1.主要介绍几个移动端常用的单位rem.vw.vh,配合传统的px.百分比.<viewport>标签,兼容适配移动端的各种分辨率的手机端. rm : 这个单位是以父元素为标准来进行计算 , ...

  9. 基本的文件I/O

    基本的文件 I/O 抽象基类 Stream 支持读取和写入字节. Stream 集成了异步支持. 其默认实现根据其相应的异步方法来定义同步读取和写入,反之亦然. 所有表示流的类都是从 Stream 类 ...

  10. wsgi初探

    大半夜的不睡觉,起来看技术文档,我这是什么精神啊~ ok 本文的大部分内容都是阅读 http://wsgi.readthedocs.org/en/latest/ 得来的.下面开始研究 wsgi wsg ...