当前位置:网站首页>4275. Dijkstra序列
4275. Dijkstra序列
2022-06-24 07:07:00 【Ray.C.L】

思路:直接跑一遍dijkstra看是否与序列中加入的顶点顺序相同
代码:
#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;
}
边栏推荐
- liunx 更改 vsftpd 的端口号
- 数据中台:中台实践与总结
- MySQL | 存储《康师傅MySQL从入门到高级》笔记
- It is enough to read this article about ETL. Three minutes will let you understand what ETL is
- 利用sonar做代码检查
- String to Base64
- There was an error checking the latest version of pip
- 【LeetCode】541. 反转字符串 II
- 小程序云数据,数据请求一个集合数据的方法
- A tip to read on Medium for free
猜你喜欢

WebRTC系列-网络传输之5选择最优connection切换

The form image uploaded in chorme cannot view the binary image information of the request body

Centos7 installation of jdk8, mysql5.7 and Navicat connection to virtual machine MySQL and solutions (solutions to MySQL download errors are attached)
![打印出来的对象是[object object],解决方法](/img/fc/9199e26b827a1c6304fcd250f2301e.png)
打印出来的对象是[object object],解决方法
![[pytoch basic tutorial 31] youtubednn model analysis](/img/18/dbeab69894583f6e5230772ce44652.png)
[pytoch basic tutorial 31] youtubednn model analysis

【LeetCode】415. 字符串相加

OpenCV每日函数 结构分析和形状描述符(7) 寻找多边形(轮廓)/旋转矩形交集

MySQL | 视图《康师傅MySQL从入门到高级》笔记

input的聚焦后的边框问题

“不平凡的代理初始值设定不受支持”,出现的原因及解决方法
随机推荐
【牛客】把字符串转换成整数
Jenkins自动化部署,连接不到所依赖的服务【已解决】
数据库迁移从PostgreSQL迁移到 MYSQL
利用ngrok做内网穿透
PHP code encryption + extended decryption practice
剑指 Offer 55 - I. 二叉树的深度-dfs法
QT source code analysis -- QObject (2)
110. 平衡二叉树-递归法
[force deduction 10 days SQL introduction] Day3
mysql组合索引的有序性
教程篇(5.0) 08. Fortinet安全架构集成与FortiXDR * FortiEDR * Fortinet 网络安全专家 NSE 5
Several schemes of PHP code encryption
疫情、失业,2022,我们高喊着摆烂和躺平!
数据中台:国内大厂中台建设架构集锦
Background management of uniapp hot update
String to Base64
为什么ping不通,而traceroute却可以通
数云发布2022美妆行业全域消费者数字化经营白皮书:全域增长破解营销难题
Get screen width and height tool class
数据中台:数据中台技术架构详解