当前位置:网站首页>[training day3] reconstruction of roads [SPFA]
[training day3] reconstruction of roads [SPFA]
2022-07-27 13:57:00 【VL——MOESR】

Ideas :
Run straight spfa That's it
c o d e code code
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
using namespace std;
const int MAXN = 105;
int n, m, d;
int ma[MAXN][MAXN], dis[MAXN];
bool v[MAXN], f[MAXN][MAXN];
int head[MAXN], tot;
queue<int> q;
bool Floyd() {
for(int k = 1; k <= n; k ++)
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= n; j ++)
f[i][j] = (f[i][j] | (f[i][k] & f[k][j]));
}
int main() {
freopen("road.in", "r", stdin);
freopen("road.out", "w", stdout);
scanf("%d%d", &n, &m);
for(int i = 1; i <= m; i ++) {
int x, y, z;
scanf("%d%d%d", &x, &y, &z);
ma[x][y] = ma[y][x] = z;
f[x][y] = f[y][x] = 1;
}
scanf("%d", &d);
for(int i = 1; i <= d; i ++) {
int x, y;
scanf("%d%d", &x, &y);
f[x][y] = f[y][x] = 0;
}
Floyd();
int A, B;
scanf("%d%d", &A, &B);
memset(dis, 0x3f, sizeof(dis));
v[A] = 1, dis[A] = 0, q.push(A);
while(!q.empty()) {
int x = q.front();
q.pop();
for(int i = 1; i <= n; i ++) {
int w = 0;
if(f[x][i] == 1) w = 0;
else if(ma[x][i] != 0) w = ma[x][i];
else w = dis[0];
if(dis[x] + w < dis[i]) {
dis[i] = dis[x] + w;
if(v[i] == 0) {
v[i] = 1;
q.push(i);
}
}
}
v[x] = 0;
}
printf("%d", dis[B]);
return 0;
}
边栏推荐
- 【2022-07-25】
- Crop the large size image of target detection into a fixed size image
- [internship experience] add your own implementation method to the date tool class
- [introduction to C language] zzulioj 1021-1025
- 《C语言》函数栈帧的创建与销毁--(内功)
- 【2022-07-25】
- LeetCode报错及其解决方案
- Wechat campus laundry applet graduation design finished product of applet completion work (3) background function
- 小程序毕设作品之微信校园洗衣小程序毕业设计成品(7)中期检查报告
- Wechat campus laundry applet graduation design finished product (5) assignment
猜你喜欢

English grammar_ Personal pronoun

Network packet loss, network delay? This artifact helps you get everything done!

Wechat campus laundry applet graduation design finished product (7) Interim inspection report

Keras深度学习实战——推荐系统数据编码

在“元宇宙空间”UTONMOS将打开虚实结合的数字世界
idea Gradle7.0+ :Could not find method compile()

《C语言》函数栈帧的创建与销毁--(内功)

纯c手写线程池

剑指Offer 07 重建二叉树 -- 从中序与后序遍历序列构造二叉树

基于C语言实现线性表的建立、插入、删除、查找等基本操作
随机推荐
《C语言》函数栈帧的创建与销毁--(内功)
Oppo self-developed large-scale knowledge map and its application in digital intelligence engineering
opencv图像的缩放平移及旋转
Interviewers often ask: how to set up a "message queue" and "delayed message queue"?
关于max做动画的一些关键信息(shift+v)
在“元宇宙空间”UTONMOS将打开虚实结合的数字世界
SQL教程之 SQL 聚合函数入门教程
将目标检测大尺寸图片裁剪成固定尺寸图片
Realize the basic operations such as the establishment, insertion, deletion and search of linear tables based on C language
Product manager experience 100 (XI) - Strategic Product Manager: model and methodology
【每日一题】1206. 设计跳表
[introduction to C language] zzulioj 1021-1025
Software system architecture designer concise tutorial | software system modeling
Structural thinking
Design of network abnormal traffic analysis system
Converter registration of easyexcel
记账软件如何查看收入支出
软考 系统架构设计师 简明教程 | 软件测试
JS divides the array into two-dimensional arrays according to the specified attribute values
井贤栋等蚂蚁集团高管不再担任阿里合伙人 确保独立决策