当前位置:网站首页>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;
}
边栏推荐
- One article explains in detail | those things about growth
- Qingcloud based "real estate integration" cloud solution
- 1844. replace all numbers with characters
- Xiaohei ai4code code baseline nibble 1
- 关于 GIN 的路由树
- 快慢指针系列
- GradScaler MaxClipGradScaler
- Scheme of alcohol concentration tester based on single chip microcomputer
- opencv最大值滤波(不局限于图像)
- 216. combined summation III enumeration method
猜你喜欢
关于 GIN 的路由树
2022-06-23:给定一个非负数组,任意选择数字,使累加和最大且为7的倍数,返回最大累加和。 n比较大,10的5次方。 来自美团。3.26笔试。
Become an IEEE student member
JS to find and update the specified value in the object through the key
【牛客】把字符串转换成整数
"Unusual proxy initial value setting is not supported", causes and Solutions
陆奇:我现在最看好这四大技术趋势
“论解不了数独所以选择做个数独游戏这件事”
【PyTorch基础教程30】DSSM双塔模型代码解析
Opencv maximum filtering (not limited to images)
随机推荐
Xiaohei ai4code code baseline nibble 1
[quantitative investment] discrete Fourier transform to calculate array period
【NOI模拟赛】摆(线性代数,杜教筛)
打印出来的对象是[object object],解决方法
Solving linear equations with MATLAB ax=b
Database migration from PostgreSQL to MySQL
520. 检测大写字母
216. 组合总和 III-枚举法
【LeetCode】415. 字符串相加
opencv最大值滤波(不局限于图像)
Idea another line shortcut
every()、map()、forEarch()方法。数组里面有对象的情况
orb slam build bug: undefined reference to symbol ‘_ ZN5boost6system15system_ categoryEv‘
华为路由器:ipsec技术
玄铁E906移植----番外0:玄铁C906仿真环境搭建
疫情、失业,2022,我们高喊着摆烂和躺平!
Earthly container image construction tool -- the road to dream
Distributed | how to make "secret calls" with dble
微博撰写-流程图-序列图-甘特图-mermaid流程图-效果不错
[MySQL from introduction to mastery] [advanced part] (I) character set modification and underlying principle