当前位置:网站首页>【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;
}
边栏推荐
猜你喜欢

杰理之SD卡切回蓝牙没有作用【篇】

容易混淆的指针知识点

【服务器数据恢复】Ext4文件系统fsck后mount不上并报错的数据修复案例

钉钉与RStudio快捷方式冲突--钉钉快捷键设置

JVM学习——1——虚拟机基础概念

EDI对接 New York & Company案例
Construction and practice of full stack code test coverage and use case discovery system

抖音直播新号怎么起号?抖音直播间不进人怎么办?

MySQL:redo log日志——笔记自用

2022 High-altitude installation, maintenance, and demolition exam practice questions and mock exams
随机推荐
MySQL:redo log日志——笔记自用
simple math formula calculation
自动化测试-图片中添加文字注释,添加到allure测试报告中
JS-DOM--全局DOM对象document-history-location-navigator-screen-window
Ali YunTianChi competition problem (deep learning) - video enhancement (complete code)
全栈代码测试覆盖率及用例发现系统的建设和实践
Base64编码和图片转化
【暑期每日一题】洛谷 P1176 路径计数2
基于ABP和Magicodes实现Excel导出操作
浅谈进程与其创建方式
“error“: { “root_cause“: [{ “type“: “circuit_breaking_exception“, “reason“: “[parent] D [solved]
LN论文、五种归一化原理和实现
ABP中的数据过滤器
LeetCode-从链表中删去总和值为零的连续结点
杰理之智能充电仓低电发码关机 触摸不开机【篇】
2022R1快开门式压力容器操作考试模拟100题及在线模拟考试
钉钉与RStudio快捷方式冲突--钉钉快捷键设置
MySql.Data.MySqlClient.DBNull
MySQL:意向共享锁和意向排它锁 | 死锁 | 锁的优化
新一代CMDB构建方法,是能够给企业带来收益的