当前位置:网站首页>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;
}
边栏推荐
- [force deduction 10 days SQL introduction] Day3
- IDEA另起一行快捷键
- Telnet port login method with user name for liunx server
- A tip to read on Medium for free
- 数据中台:民生银行的数据中台实践方案
- 520. detect capital letters
- leetcode 1642. Furthest building you can reach
- What is the future development trend of Business Intelligence BI
- 【使用 PicGo+腾讯云对象存储COS 作为图床】
- [10 day SQL introduction] Day2
猜你喜欢

What is the future development trend of Business Intelligence BI

【Pytorch基础教程31】YoutubeDNN模型解析

YOLOX backbone——CSPDarknet的实现

数据中台:数据采集和抽取的技术栈详解
![[noi Simulation Competition] geiguo and time chicken (structure)](/img/4c/ed1b5bc2bed653c49b8b7922ce1674.png)
[noi Simulation Competition] geiguo and time chicken (structure)

原生小程序用画布制作海报,等比例缩放,和uniapp差不多就是写法有点不同

A tip to read on Medium for free

【LeetCode】541. 反转字符串 II
![[quantitative investment] discrete Fourier transform to calculate array period](/img/0d/aac02463ff403fb1ff871af5ff91fa.png)
[quantitative investment] discrete Fourier transform to calculate array period

關於ETL看這篇文章就够了,三分鐘讓你明白什麼是ETL
随机推荐
MySQL——SQL语句
项目部署相关
mysql写的代码数据 增删查改等等
Liunx Mysql安装
Prompt code when MySQL inserts Chinese data due to character set problems: 1366
数据中台:民生银行的数据中台实践方案
【LeetCode】387. 字符串中的第一个唯一字符
【E325: ATTENTION】vim编辑时报错
快慢指针系列
Floating error waiting for changelog lock
216. 组合总和 III-枚举法
【PyTorch基础教程30】DSSM双塔模型代码解析
opencv最大值滤波(不局限于图像)
Double pointer analog
MBA-day25 最值问题-应用题
leetcode 1268. Search suggestions system
[MySQL from introduction to mastery] [advanced part] (I) character set modification and underlying principle
leetcode 1642. Furthest building you can reach
数据中台:国内大厂中台建设架构集锦
Database migration from PostgreSQL to MySQL