Sicily. Walk This Way
来源:互联网 发布:linux vi 复制整行 编辑:程序博客网 时间:2024/04/28 01:30
在这道题中用了个小技巧,根据是否能乘车来判断距离,若能乘车,则距离为0,不能则为dis
代码如下
#include <iostream>#include <stack>#include <cstdio>#include <queue>#include <vector>#include <algorithm>#include <iomanip>#include <cstring>using namespace std;const int maxn = 10001;int dis[101][101];bool vis[101];int minDis[101];int main(){int tst;scanf("%d", &tst);while(tst--){int n, m;int c1, c2, d, bus;int start, end;scanf("%d%d", &n, &m);//initializefor(int i = 0; i < 101; i++){vis[i] = false;for(int j = 0; j < 101; j++)dis[i][j] = maxn;}//record the mapfor(int i = 0; i < m; i++){scanf("%d%d%d%d", &c1, &c2, &d, &bus);dis[c1][c2] = (bus == 1)?0:d;dis[c2][c1] = (bus == 1)?0:d;}scanf("%d%d", &start, &end);//Dijkstrafor(int i = 0; i < n; i++)minDis[i] = dis[start][i];vis[start] = true;for(int i = 1; i < n; i++){int tempDis = maxn;int nextPoint;for(int k = 0; k < n; k++){if(tempDis > minDis[k] && !vis[k]){tempDis = minDis[k];nextPoint = k;}}vis[nextPoint] = true;//updatefor(int k = 0; k < n; k++){if(minDis[k] > dis[nextPoint][k] + tempDis && !vis[k])minDis[k] = dis[nextPoint][k] + tempDis;}}printf(vis[end]?"%d\n":"-1\n", minDis[end]);}return 0;}
0 0
- Sicily. Walk This Way
- Sicily 4478. Walk This Way
- J. Walk This Way
- Sicily 1415. Honeycomb Walk
- Sicily 1120. Walk Through the For
- my way begin at this day!
- walk
- Walk
- Walk
- walk
- Walk
- Walk
- Walk
- WALK! WALK!! WALK!!!
- Is this a good/right way to use generic interface?
- My thoughts during this portentous walk were, I am afraid, rather
- This application has requested the Runtime to terminate it in an unusual way.
- Why did we implement Swing in this way?(为什么Swing要这样实现呢?)
- 安装nodejs
- 族邹姿尊谞鬃庄租住椎籽转渍籽揍滋作赚
- NPOI
- 壮啄茁卒组紫姿赘撰桌遵浊滓淄咨庄滋鬃
- tomcat部署war包步骤及出现的问题和解决方法
- Sicily. Walk This Way
- 滋锥字自棕祝左祖阻咨座钻壮祖自综赚谞
- Java笔记整理——数组
- Java连接MySQL数据库
- Validate Binary Search Tree Leetcode Python
- 昨浊灼纵着装总族尊租坠坠鬃爪座谆捉诅
- Blinky.c(171): warning: #1-D: last line of file ends without a newline
- 添加区域视图 找到多个与名为“home”的控制器匹配的类型
- XML中引入Schema的介绍