当前位置:网站首页>[UNR #6 A] Noodle-based road (shortest path)
[UNR #6 A] Noodle-based road (shortest path)
2022-08-09 04:49:00 【SSL_TJH】
face-to-face road
题目链接:UNR #6 A
题目大意
给你一个无向图,Then each edge has a length,然后你在 1 号点,有不超过 20 Individuals at their respective points,Each person can walk one unit of length per unit of time.
Then ask how long it will take you at least to meet everyone in turn.(可以在边上)
思路
First find the order is ok,Just want these people to reconcile.
And then found out that he wasn't special either,So the problem is the time to get to a place max \max max 取 min \min min.
(Run directly at each point as the starting point dij Get the distance to each location)
Each point can then be enumerated first,Then consider the edges.
Consider getting a demarcation point,If the distance to the left point is less than or equal to the dividing point,Then go to the point on the left,Otherwise go to the point on the right.
The dividing point only needs to enumerate the distance from each point to the left point.
然后好了.
代码
#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;
}
边栏推荐
- equals and ==
- 杰理之SD卡切回蓝牙没有作用【篇】
- Harmony OS ets ArkUI 】 【 】 development create a view and building layout
- 【开发者必看】【push kit】推送服务服务典型问题合集2
- 2022下半年深圳信息系统项目管理师认证招生简章
- P1163 银行贷款
- A case of missing heritability
- 阿里云天池大赛赛题(机器学习)——O2O优惠券预测(完整代码)
- 2022 Security Officer-A Certificate Special Work Permit Exam Question Bank and Online Mock Exam
- Efficient review of deep learning DL, CV, NLP
猜你喜欢
杰理之智能充电仓低电发码关机 触摸不开机【篇】
存储系统架构演变
2022 Security Officer-A Certificate Special Work Permit Exam Question Bank and Online Mock Exam
特征工程实战篇
ABP 6.0.0-rc.1的新特性
leetcode:402. 移掉 K 位数字
JS-DOM-对象的事件onload、匿名函数、this
GraalVM安装
Cluster deployment using ceph-deploycep with 3 disks as dedicated osd
JS-DOM-全局、局部、隐式变量,数组()\函数、 prompt输入对话框、confirm(确定用户的决定-弹出对话框)
随机推荐
整除性质1
【Harmony OS】【FAQ】鸿蒙问题合集1
Dingding conflicts with RStudio shortcuts--Dingding shortcut settings
2022 High Voltage Electrician Exam Questions and Answers
数量遗传学遗传力计算1:亲子回归方法
【暑期每日一题】洛谷 P8086 『JROI-5』Music
高效回顾深度学习DL、CV、NLP
基于ABP和Magicodes实现Excel导出操作
Integer multiple series
阿里云天池大赛赛题(机器学习)——阿里云安全恶意程序检测(完整代码)
数量遗传学遗传力计算2:半同胞和全同胞
MySQL:redo log日志——笔记自用
leetcode:316. 去除重复字母
杰理之SD卡切回蓝牙没有作用【篇】
XJTUSE Professional Course and Experiment Guide
【ITRA】2022年ITRA赛事注册流程 从0-1
Harmony OS ets ArkUI 】 【 】 development create a view and building layout
Introduction to JVM garbage collection mechanism
php使用phpoffice/phpspreadsheet导入导出excel表格
TCP/IP协议中分包与重组原理介绍、分片偏移量的计算方法、IPv4报文格式