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. RANS VS LES

    Turbulence models

  2. 【Codeforces 977F】Consecutive Subsequence

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 设f[i]表示i作为序列的最后一个数字,最长的连续序列的长度. 用f[i]和f[i-1]+1来转移即可 [代码] import java.io ...

  3. [luoguP3146] [USACO16OPEN]248(区间DP)

    传送门 f[i][j]表示区间 i-j 合并的最大值 转移: 若f[i][k] && f[k+1][j] && f[i][k] == f[k+1][j] --> ...

  4. [国家集训队2010]小Z的袜子

    ★★★   输入文件:hose.in   输出文件:hose.out   简单对比 时间限制:1 s   内存限制:512 MB [题目描述] 作为一个生活散漫的人,小Z每天早上都要耗费很久从一堆五颜 ...

  5. Extended symmetrical multiprocessor architecture

    An architecture for an extended multiprocessor (XMP) computer system is provided. The XMP computer s ...

  6. 复习es6-let和const

    1.声明变量的方法 es5 : var   function es6 : var   function   let    const   class 2.let(const)与var 不同 let不能 ...

  7. FLASH BACK

    overview of different flashback technologies flashback query(including flashback query, flashback ve ...

  8. NetCore发布WebApi项目到IIS服务器中

    1.确保已在机器上安装Net Core Runtime,,下载地址: https://dotnet.microsoft.com/download 2.点击WebApi项目右键->发布,选择IIS ...

  9. CentOS 7: 配置Network

    Command Mode Step 1 » Network interface config files are located in /etc/sysconfig/network-scripts/  ...

  10. Date.parse函数的兼容问题

    由于要用Date.parse函数解析一个日期时间的字符串.在谷歌浏览器中解析成功,但是IE.火狐中却不行. 不知何故.firefox对于类似"2010-12-20 15:55:00" ...