$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 ;
}
随机推荐
- Code128条形码如何计算其宽度?如何得出其校验位?
原文链接 Code128条形码是一个非常高密的字母数字条码,能够存储需要的编码数据,它可以编码所有128个ASCII码字符,它使用最少的空间. 在Code128符号体系中,每个数据字符编码都是由11个 ...
- OpenCV+Python识别车牌和字符分割的实现
本篇文章主要基于python语言和OpenCV库(cv2)进行车牌区域识别和字符分割,开篇之前针对在python中安装opencv的环境这里不做介绍,可以自行安装配置! 车牌号检测需要大致分为四个部分 ...
- 泛型约束 ---类型参数上的限制(where T:class,new())
今天遇到的一个问题,找到了解决办法,收藏以后记得看一下!
- jetty添加容器容器提供包
在tomcat的使用中,我们常常会吧容器提供的包放入:TOMCAT_HOME\lib下, 比如mysql-connection-java-version.jar 在使用jetty容器的时候,若要让容器 ...
- 20170613NOIP模拟赛
共3道题目,时间3小时 题目非原创,仅限校内交流使用 题目名称 Graph Incr Permutation 文件名 graph incr permutation 输入文件 graph.in incr ...
- 洛谷—— P3811 【模板】乘法逆元
https://www.luogu.org/problem/show?pid=3811 题目背景 这是一道模板题 题目描述 给定n,p求1~n中所有整数在模p意义下的乘法逆元. 输入输出格式 输入格式 ...
- YAML/Properties配置文件与Spring Boot(转)
多年来,Java开发人员依赖于属性文件或xml文件来指定应用程序配置.在企业应用程序中,人们可以为每个环境(如开发,分段和生产)创建单独的文件,以定义相应环境的属性.但是,通过Spring引导,我们可 ...
- Oracle中的 row_number() over (partition by order by ) 用法
oracle 里面经常这样用 select col1,col2..., row_number() over (partition by colx order by coly) from table_n ...
- mybatis指定jdbctype
MyBatis 插入空值时,需要指定JdbcType mybatis insert空值报空值异常,但是在pl/sql不会提示错误,主要原因是mybatis无法进行转换 所以在MyBatis映射文件中要 ...
- python 除法总返回浮点
python 除法总返回浮点,要返回整型需要用//: print(type(4/2),type(4//2)) #<class 'float'> <class 'int'>