当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
![打印出来的对象是[object object],解决方法](/img/fc/9199e26b827a1c6304fcd250f2301e.png)
打印出来的对象是[object object],解决方法

Wan Weiwei, a researcher from Osaka University, Japan, introduced the rapid integration method and application of robot based on WRS system

opencv最大值滤波(不局限于图像)

开源之夏中选名单已公示,基础软件领域成为今年的热门申请

一文详解|增长那些事儿

The form image uploaded in chorme cannot view the binary image information of the request body
![[pytoch basic tutorial 31] youtubednn model analysis](/img/18/dbeab69894583f6e5230772ce44652.png)
[pytoch basic tutorial 31] youtubednn model analysis

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

数据中台:数据采集和抽取的技术栈详解

Prompt code when MySQL inserts Chinese data due to character set problems: 1366
随机推荐
开源之夏中选名单已公示,基础软件领域成为今年的热门申请
表单图片上传在Chorme中无法查看请求体的二进制图片信息
Smart power plant: how to make use of easycvr to build a safe, stable, green and environment-friendly intelligent inspection platform
Jenkins自动化部署,连接不到所依赖的服务【已解决】
It is enough to read this article about ETL. Three minutes will let you understand what ETL is
rsync做文件备份
520. 检测大写字母
Using ngrok for intranet penetration
数据平台简介
The pie chart with dimension lines can set various parameter options
關於ETL看這篇文章就够了,三分鐘讓你明白什麼是ETL
基于QingCloud的 “房地一体” 云解决方案
【LeetCode】387. 字符串中的第一个唯一字符
第七章 操作位和位串(三)
dataX使用指南
关于ETL看这篇文章就够了,三分钟让你明白什么是ETL
What is graph neural network? Figure what is the use of neural networks?
RuntimeError: Missing dependencies:XXX
Become an IEEE student member
Introduction to data platform