JZOJ 5196. 【NOIP2017提高组模拟7.3】B
5196. 【NOIP2017提高组模拟7.3】B
Description
Input
Output
Sample Input
5 10 40
2 4 80
2 3 57
1 2 16
2 5 49
Sample Output
16
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 300007
#define LL long long
using namespace std;
LL n, S, E, ls[N], tot, Ma[N], Size[N], sum, root, Len ;
LL d[N], ans;
bool v[N];
struct edge
{
LL to, next, w;
}e[N * ];
struct arr
{
LL dis;
int fa;
}a[N]; inline void Add(int x, int y, int w)
{
e[++tot].to = y;
e[tot].w = w;
e[tot].next = ls[x];
ls[x] = tot;
} inline void Getroot(int x, int fa)
{
Ma[x] = , Size[x] = ;
for (int i = ls[x]; i; i = e[i].next)
{
int visit = e[i].to;
if (v[visit] || visit == fa) continue;
Getroot(visit, x);
Size[x] += Size[visit];
Ma[x] = max(Size[visit], Ma[x]);
}
Ma[x] = max(Ma[x], sum - Size[x]);
if (Ma[x] < Ma[root]) root = x;
} inline void Getval(int x, int fa, int zs)
{
a[++Len].dis = d[x];
a[Len].fa = zs;
for (int i = ls[x]; i; i = e[i].next)
{
int visit = e[i].to;
if (v[visit] || visit == fa) continue;
d[visit] = d[x] + e[i].w;
if (!zs) Getval(visit, x, visit);
else Getval(visit, x, zs);
}
} int cmp(arr x, arr y)
{
return x.dis < y.dis;
} inline LL Acu(int x)
{
Len = , d[x] = ;
Getval(x, , );
sort(a + , a + Len + , cmp);
int l = , r = Len;
for (; l < r; )
{
if (a[l].fa == a[r].fa)
{
if (a[l].dis + a[r - ].dis < S) l++;
else r--;
}
else
{
if (a[l].dis + a[r].dis >= S)
{
ans = min(ans,(LL)(a[l].dis + a[r].dis));
r--;
}
else l++;
}
}
} inline void work(int x)
{
Acu(x);
v[x] = ;
for (int i = ls[x]; i; i = e[i].next)
{
int visit = e[i].to;
if (v[visit]) continue;
sum = Size[visit];
root = ;
Getroot(visit, );
work(root);
}
} int main()
{
scanf("%d%d%d", &n, &S, &E);
memset(v, , sizeof(v));
memset(ls, , sizeof(ls));
for (int i = ; i <= n - ; i++)
{
int u, v, w;
scanf("%d%d%d", &u, &v, &w);
Add(u, v, w);
Add(v, u, w);
}
ans = 0x3f3f3f3f;
sum = n;
Ma[] = 0x3f3f3f3f;
Getroot(, );
work(root);
if (ans > E) printf("-1");
else printf("%lld", ans);
}
JZOJ 5196. 【NOIP2017提高组模拟7.3】B的更多相关文章
- [jzoj 5178] [NOIP2017提高组模拟6.28] So many prefix? 解题报告(KMP+DP)
题目链接: https://jzoj.net/senior/#main/show/5178 题目: 题解: 我们定义$f[pos]$表示以位置pos为后缀的字符串对答案的贡献,答案就是$\sum_{i ...
- [jzoj 5177] [NOIP2017提高组模拟6.28] TRAVEL 解题报告 (二分)
题目链接: https://jzoj.net/senior/#main/show/5177 题目: 题解: 首先选出的泡泡怪一定是连续的一段 L,R 然后 L 一定属于虫洞左边界中的某一个 R 也同样 ...
- JZOJ 5197. 【NOIP2017提高组模拟7.3】C
5197. [NOIP2017提高组模拟7.3]C Time Limits: 1000 ms Memory Limits: 262144 KB Detailed Limits Goto Pro ...
- JZOJ 5195. 【NOIP2017提高组模拟7.3】A
5195. [NOIP2017提高组模拟7.3]A Time Limits: 1000 ms Memory Limits: 262144 KB Detailed Limits Goto Pro ...
- JZOJ 5184. 【NOIP2017提高组模拟6.29】Gift
5184. [NOIP2017提高组模拟6.29]Gift (Standard IO) Time Limits: 1000 ms Memory Limits: 262144 KB Detailed ...
- JZOJ 5185. 【NOIP2017提高组模拟6.30】tty's sequence
5185. [NOIP2017提高组模拟6.30]tty's sequence (Standard IO) Time Limits: 1000 ms Memory Limits: 262144 KB ...
- NOIP2017提高组 模拟赛15(总结)
NOIP2017提高组 模拟赛15(总结) 第一题 讨厌整除的小明 [题目描述] 小明作为一个数学迷,总会出于数字的一些性质喜欢上某个数字,然而当他喜欢数字k的时候,却十分讨厌那些能够整除k而比k小的 ...
- NOIP2017提高组 模拟赛13(总结)
NOIP2017提高组 模拟赛13(总结) 第一题 函数 [题目描述] [输入格式] 三个整数. 1≤t<10^9+7,2≤l≤r≤5*10^6 [输出格式] 一个整数. [输出样例] 2 2 ...
- NOIP2017提高组模拟赛 10 (总结)
NOIP2017提高组模拟赛 10 (总结) 第一题 机密信息 FJ有个很奇怪的习惯,他把他所有的机密信息都存放在一个叫机密盘的磁盘分区里,然而这个机密盘中却没有一个文件,那他是怎么存放信息呢?聪明的 ...
随机推荐
- C - Watchmen
题目链接:https://vjudge.net/contest/237394#problem/C Watchmen are in a danger and Doctor Manhattan toget ...
- Shell笔试题3
1.查找当前目录中所有大于500M的文件,把这些文件名写到一个文本文件中,并统计其个数.find ./ -size +500M -type f | tee file_list | wc -l 2.在目 ...
- vue3.0学习笔记(二)
一.选择合适的ide 推荐使用vs code编辑器,界面清晰.使用方便,控制台功能很好用.webstorm也可以,看个人喜好. 二.ui框架选择 目前,pc端一般是选择element ui(饿了么), ...
- 《Head First 设计模式》之模板方法模式——冲泡咖啡和茶
模板方法模式(Template) ——在一个方法中定义了一个算法的骨架,而将一些步骤延迟到子类中.模板方法使得子类可以在不改变算法结构的情况下,重新定义算法中的某些步骤. 好莱坞原则:别调用(打电话给 ...
- 从零开始的全栈工程师——js篇2.17(属性和节点获取)
DOM 一.节点树状图 Document>documentElement>body>tagname 二.常用的节点类型 元素节点(标签) 文本节点(文本节点) 属性节点(标签里的属性 ...
- nodejs的会话总结
前言: http是一个无状态协议,所以客户端每次发出请求时,下一次请求就无法得知上一次请求所包含的状态数据,那么如何能把一个用户的状态数据关联起来?1.cookie 一开始,人们采用cookie这门技 ...
- Google pieCharts的学习
在公司项目开发过程中, 尤其是在网站的开发过程中,用到很多的前端的插件,在这里, 我简单介绍下近期Google pieCharts的是使用方法 https://developers.google.co ...
- python logging 模块记录日志
#日志记录到多文件示例 import logging def error_log(message): file_1_1 = logging.FileHandler('error.log', 'a+', ...
- Oracle添加自增长字段方法步骤
第一步:创建自增长序列 CREATE SEQUENCE ZH_ALARM_INFO_SEQ--自动增长列 INCREMENT BY 1 -- 每次加几个 START WITH 1 -- 从1开始计数 ...
- 基于spark Mllib(ML)聚类实战
写在前面的话:由于spark2.0.0之后ML中才包括LDA,GaussianMixture 模型,这里k-means用的是ML模块做测试,LDA,GaussianMixture 则用的是ML ...