• $P3931 SAC E一道难题 Tree$


    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 ;
    }
    
    
  • 相关阅读:
    dubbo的超时机制
    今天又遇到之前的问题,后端返回数据long到前端失真
    如何在一台机子上配置两个github
    当sum函数返回null时处理
    Linux中zookeeper安装
    Linux常用指令
    sql执行顺序
    固定时间刷新某个固定值 java
    docker基础
    python之CSS
  • 原文地址:https://www.cnblogs.com/qf-breeze/p/10657296.html
Copyright © 2020-2023  润新知