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有个很奇怪的习惯,他把他所有的机密信息都存放在一个叫机密盘的磁盘分区里,然而这个机密盘中却没有一个文件,那他是怎么存放信息呢?聪明的 ...
随机推荐
- EasyTouch3.16 初步使用
- oracle 中的null与''
1.先看看Null与''在oracle中的表现 C:\Users\zen>sqlplus hr/hr SQL Production :: Copyright (c) , , Oracle. Al ...
- Hadoop 3节点集群无法成功启动zookeeper
今天在集群上跑程序的时候遇到了zookeeper无法成功启动的问题,先分别启动了主节点和从节点的zookeeper进程,并且通过jps也看到zookeeper进程已经启动了,但通过指令查看进程状态的时 ...
- ElasticSearch安装和核心概念
1.ElasticSearch安装 elasticsearch的安装超级easy,解压即用(要事先安装好java环境). 到官网 http://www.elasticsearch.org下载最新版的 ...
- python类型之间的转换
*int(x,base=10)x字符串或数字,base进制数,默认十进制 浮点转为整数 *float 整数转换为浮点型 *complex(1,2) 转换为复数 *str(10)将对象转换为字符串 *r ...
- Java基础反射-调用类
Student类 package com.test.wang; import java.lang.reflect.Constructor; import java.lang.reflect.Field ...
- [LeetCode]3. Longest Substring Without Repeating Characters无重复字符的最长子串
Given a string, find the length of the longest substring without repeating characters. Example 1: In ...
- pandas:数据分析
一.介绍 pandas是一个强大的Python数据分析的工具包,是基于NumPy构建的. 1.主要功能 具备对其功能的数据结构DataFrame.Series 集成时间序列功能 提供丰富的数学运算和操 ...
- BZOJ4355: Play with sequence(吉司机线段树)
题意 题目链接 Sol 传说中的吉司机线段树??感觉和BZOJ冒险那题差不多,就是强行剪枝... 这题最坑的地方在于对于操作1,$C >= 0$, 操作2中需要对0取max,$a[i] > ...
- @Enable*注解的工作原理
@EnableAspectJAutoProxy @EnableAsync @EnableScheduling @EnableWebMv @EnableConfigurationProperties @ ...