当前位置:网站首页>4275. Dijkstra sequence
4275. Dijkstra sequence
2022-06-24 08:57:00 【Ray. C.L】

Ideas : Run straight through dijkstra See if the order of vertices added in the sequence is the same
Code :
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1010, INF = 0x3f3f3f3f;
int dis[N],g[N][N];
bool st[N];
int q[N];
int n,m;
bool dijkstra(){
memset(st, false, sizeof st);
memset(dis, INF, sizeof dis);
dis[q[0]] = 0;
for(int i = 0; i < n; i++){
int t=q[i];
for(int j = 1; j <= n; j++)
if(!st[j] && dis[j] < dis[t])
return false;
st[t] = true;
for(int j = 1; j <=n; j++)
dis[j] = min(dis[j],dis[t] + g[t][j]);
}
return true;
}
int main()
{
scanf("%d%d", &n, &m);
memset(g, INF, sizeof g);
while (m -- ){
int a,b,c;
scanf("%d%d%d", &a, &b, &c);
g[a][b]=g[b][a]=c;
}
int k;
scanf("%d", &k);
while( k-- ){
for(int i=0;i<n;i++)
scanf("%d", &q[i]);
if(dijkstra()) puts("Yes");
else puts("No");
}
return 0;
}
边栏推荐
- [quantitative investment] discrete Fourier transform to calculate array period
- 什么是图神经网络?图神经网络有什么用?
- 【E325: ATTENTION】vim编辑时报错
- 疫情、失业,2022,我们高喊着摆烂和躺平!
- How does the tunnel mobile inspection track robot monitor 24 hours to ensure the safety of tunnel construction?
- 何时使用RDD和DataFrame/DataSet
- 2021-05-20computed和watch应用与区别
- MBA-day25 最值问题-应用题
- input的聚焦后的边框问题
- 【NOI模拟赛】给国与时光鸡(构造)
猜你喜欢

教程篇(5.0) 08. Fortinet安全架构集成与FortiXDR * FortiEDR * Fortinet 网络安全专家 NSE 5

Xiaohei ai4code code baseline nibble 1

Distributed | how to make "secret calls" with dble

【NOI模拟赛】寄(树形DP)

Data middle office: detailed explanation of technical architecture of data middle office

uniapp 开发多端项目如何配置环境变量以及区分环境打包

用VNC Viewer的方式远程连接无需显示屏的树莓派

À propos de ETL il suffit de lire cet article, trois minutes pour vous faire comprendre ce qu'est ETL

MySQL | view notes on Master Kong MySQL from introduction to advanced

开源之夏中选名单已公示,基础软件领域成为今年的热门申请
随机推荐
Centos7 installation of jdk8, mysql5.7 and Navicat connection to virtual machine MySQL and solutions (solutions to MySQL download errors are attached)
How does the tunnel mobile inspection track robot monitor 24 hours to ensure the safety of tunnel construction?
数据中台:中台实践与总结
xargs使用技巧 —— 筑梦之路
华为路由器:GRE技术
Opencv daily function structure analysis and shape descriptor (7) finding polygon (contour) / rotating rectangle intersection
520. 检测大写字母
opencv最大值滤波(不局限于图像)
快慢指针系列
一文讲透,商业智能BI未来发展趋势如何
数据中台:数据中台技术架构详解
IDEA另起一行快捷键
Pymysql inserts data into MySQL and reports an error for no reason
One article explains in detail | those things about growth
【牛客】HJ1 字符串最后一个单词的长度
QT source code analysis -- QObject (2)
input的聚焦后的边框问题
【PyTorch基础教程30】DSSM双塔模型代码解析
Data middle office: middle office practice and summary
Array opposite pointer series