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有个很奇怪的习惯,他把他所有的机密信息都存放在一个叫机密盘的磁盘分区里,然而这个机密盘中却没有一个文件,那他是怎么存放信息呢?聪明的 ...
随机推荐
- 如何在Eclipse中正确安装Jetty插件并初步使用(图文详解)
不多说,直接上干货! 最近在做一个Storm项目,需要用到Jetty来进行展示.它类似于Tomcat. 一.eclipse中jetty插件安装 打开eclipse,依次点击菜单Help->Ecl ...
- Zipkin — 微服务链路跟踪.
一.Zipkin 介绍 Zipkin 是什么? Zipkin的官方介绍:https://zipkin.apache.org/ Zipkin是一款开源的分布式实时数据追踪系统(Distributed ...
- Spring Cloud微服务初探
学习初衷 因为加了不少优秀的知识星球,结交了更多的小伙伴,加了更多的群,每每在自我介绍的时候,都说自己是Android & Java攻城狮. 然鹅,有的小伙伴就来问了,你是搞Java的,那对S ...
- 判断两个IP地址是不是属于同一子网的方法
一个IP地址有三种写法: 第一种,单个IP,如192.168.55.28 第二种,IP/子网掩码,如192.168.55.28/255.255.255.0 第三种,IP/子网掩码长度,如192.168 ...
- Git远程推送文件太大的error解决
error: RPC failed; curl 56 OpenSSL SSL_read: SSL_ERROR_SYSCALL, errfno 10054 方法1: 改成ssh推送 方法2: 把推送的缓 ...
- 基于FCM的消息推送功能
需求背景 我方项目需要支持客户端消息推送,iOS终端可以借由苹果本身的apns很方便的实现,但是对于Android来说,必须集成第三方的SDK来处理.考虑到项目需要以及成本,我们选择使用谷歌的FCM框 ...
- idea(2017.3)的安装及快捷键的配置
一 破解安装步骤: 到IntelliJ IDEA的官网:www.jetbrains.com 然后找到下载的地方,选择自己电脑所匹配的下载安装包,这里我们选择收费版的下载 接着,点击安装包进行安装,按 ...
- 符号替换问题:请实现一个函数,将一个字符串中的空格替换成“%20”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。
public class Solution { public String replaceSpace(StringBuffer str) { String str1=str.toString(); c ...
- img IE下支持最大宽度
border:0 none; max-width: 560px; height:auto; width:expression(this.width > 600 ? "600px&quo ...
- bootstrapValidator 如何重新启用提交按钮
bootstrapValidator 使用中,由于字段检查等原因,致使提交按钮失效.如何重新启用提交按钮呢? 下面一句代码可以实现启用提交按钮: $('#loginForm').bootstrapVa ...