当前位置:网站首页>【UNR #6 A】面基之路(最短路)
【UNR #6 A】面基之路(最短路)
2022-08-09 04:43:00 【SSL_TJH】
面基之路
题目链接:UNR #6 A
题目大意
给你一个无向图,然后每条边有长度,然后你在 1 号点,有不超过 20 个人在各自的点,每个人每个单位时间能走一个单位长度。
然后问你最少要多久才能依次跟所有人相遇。(可以在边上)
思路
首先发现顺序没问题,就是要这些人会和。
然后发现自己也不是特殊的,所以问题就是走到一个地方的时间的 max \max max 取 min \min min。
(直接每个点为起点跑 dij 得到到每个位置的距离)
然后首先可以枚举每个点,然后考虑边。
考虑弄一个分界点,如果到左边点的距离小于等于分界点,那就走到左边的点,否则走到右边的点。
那分界点只要枚举每个点到左边点的距离即可。
然后好了。
代码
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define INF 0x3f3f3f3f3f3f3f3f
using namespace std;
const int N = 1e5 + 100;
struct node {
int x, to, nxt;
}e[N << 2];
int n, m, k, pl[21], X[N << 1], Y[N << 1], Z[N << 1], le[N], KK;
ll dis[21][N], ans;
priority_queue <pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > q;
bool in[N];
void add(int x, int y, int z) {
e[++KK] = (node){
z, y, le[x]}; le[x] = KK;}
void get_dis(ll *dis, int S) {
while (!q.empty()) q.pop(); q.push(make_pair(0, S));
dis[S] = 0;
memset(in, 0, sizeof(in));
while (!q.empty()) {
int now = q.top().second; q.pop();
if (in[now]) continue; in[now] = 1;
for (int i = le[now]; i; i = e[i].nxt)
if (dis[e[i].to] > dis[now] + e[i].x) {
dis[e[i].to] = dis[now] + e[i].x;
q.push(make_pair(dis[e[i].to], e[i].to));
}
}
}
int main() {
// freopen("ex_trip4.in", "r", stdin);
scanf("%d %d", &n, &m);
for (int i = 1; i <= m; i++) {
int x, y, z; scanf("%d %d %d", &x, &y, &z); z *= 2; X[i] = x; Y[i] = y; Z[i] = z;
add(x, y, z); add(y, x, z);
}
scanf("%d", &k); for (int i = 1; i <= k; i++) scanf("%d", &pl[i]); pl[0] = 1;
memset(dis, 0x7f, sizeof(dis));
for (int i = 0; i <= k; i++) get_dis(dis[i], pl[i]);
ans = INF;
for (int i = 1; i <= n; i++) {
ll now = 0; for (int j = 0; j <= k; j++) now = max(now, dis[j][i]);
ans = min(ans, now);
}
for (int i = 1; i <= m; i++) {
int x = X[i], y = Y[i], z = Z[i];
for (int j = 0; j <= k; j++) {
ll now1 = 0, now2 = 0;
for (int jj = 0; jj <= k; jj++)
if (dis[jj][x] <= dis[j][x]) now1 = max(now1, dis[jj][x]);
else now2 = max(now2, dis[jj][y]);
if (now1 > now2) swap(now1, now2);
if (now1 + z <= now2) ans = min(ans, now2);
else ans = min(ans, (now1 + now2 + z) / 2);
}
}
printf("%lld", ans);
return 0;
}
边栏推荐
- 【暑期每日一题】洛谷 P1200 [USACO1.1]你的飞碟在这儿Your Ride Is Here
- 必须指定GDAL API版本。提供一个路径使用GDAL_CONFIG gdal-config环境
- `数学` 极限, 渐进分析, 近似阶, 线性化, 线性近似, 线性函数
- TCP/IP协议中分包与重组原理介绍、分片偏移量的计算方法、IPv4报文格式
- OKR管理过程中,如何运用CFR实现组织的高效对话、反馈和认可?
- 杰理之采用mix out eq 没有作用【篇】
- 2022年安全员-B证考试练习题及在线模拟考试
- Ali YunTianChi competition problem (deep learning) - video enhancement (complete code)
- 高效回顾深度学习DL、CV、NLP
- P1163 银行贷款
猜你喜欢
全栈代码测试覆盖率及用例发现系统的建设和实践
2022 Security Officer-A Certificate Special Work Permit Exam Question Bank and Online Mock Exam
leetcode:316. 去除重复字母
Alibaba Cloud Tianchi Contest Question (Machine Learning) - Prediction of Industrial Steam Volume (Complete Code)
Talking about the process and how to create it
杰理之智能充电仓低电发码关机 触摸不开机【篇】
阿里云天池大赛赛题(机器学习)——天猫用户重复购买预测(完整代码)
杰理之SD卡切回蓝牙没有作用【篇】
ABP 6.0.0-rc.1的新特性
JVM垃圾回收机制简介
随机推荐
供应商对接Chewy的EDI需求
leetcode:316. 去除重复字母
使用ceph-deploycep集群部署,并用3个磁盘作为专用osd
安装pytorch和cuda
容易混淆的指针知识点
关于sys.path.append(‘..‘)失效
leetcode:315. 计算右侧小于当前元素的个数
抖音直播带货的4个技巧,提升直播间转化率!
BaseDexClassLoader的正确使用方式
ceph create pool, map, delete exercises
阿里云天池大赛赛题(机器学习)——工业蒸汽量预测(完整代码)
整除性质1
提升用户体验,给你的模态弹窗加个小细节
2022年安全员-A证特种作业证考试题库及在线模拟考试
整数倍数数列
特征工程实战篇
2022 Security Officer-B Certificate Exam Practice Questions and Online Mock Exam
Efficient review of deep learning DL, CV, NLP
TCP/IP协议中分包与重组原理介绍、分片偏移量的计算方法、IPv4报文格式
串扰与防护