2018年长沙理工大学第十三届程序设计竞赛 E 小木乃伊到我家 【最短路】
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 32768K,其他语言65536K
64bit IO Format: %lld
题目描述
AA的欧尼酱qwb是个考古学家,有一天qwb发现了只白白圆圆小小的木乃伊,它是个爱哭鬼却很努力。qwb想把这么可爱的小木乃伊送给
AA,于是便找上了快递姐姐,这下可让快递姐姐犯愁了,因为去往AA家的路实在太难走了(甚至有可能没有路能走到AA家),快递姐姐
找上聪明的ACMer,想请你帮忙找出最快到达AA家的路,你行吗?
输入描述:
第一行输入两个整数n和m(2<=n<=m<=200000),分别表示有n座城市和m条路,城市编号为1~n(快递姐姐所在城市为1,AA所在城市为n)。
接下来m行,每行输入3个整数u,v,w(u,v<=n,w<=100000),分别表示城市u和城市v之间有一条长为w的路。
输出描述:
输出结果占一行,输出快递姐姐到达AA家最短需要走多远的路,如果没有路能走到AA家,则输出“qwb baka”(不用输出双引号)。
示例1
输入
4 4
1 2 1
2 3 2
3 4 3
2 3 1
输出
5
思路
数据好像没那么大。。
用广搜 就能搜了
但是要注意的是 城市之间 有一条路 是双向的 所以在压入路的时候 要压入两次
AC代码
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <list>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits>
#define CLR(a, b) memset(a, (b), sizeof(a))
#define pb push_back
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair<string, int> psi;
typedef pair<string, string> pss;
typedef pair <int, ll> pil;
const double PI = acos(-1.0);
const double E = exp(1.0);
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const ll llINF = 0x3f3f3f3f3f3f3f3f;
const int maxn = 2e5 + 5;
const int MOD = 1e9;
vector <pil> G[maxn];
ll v[maxn];
int n, m;
struct node
{
int y;
ll fee;
};
void bfs()
{
int len = G[1].size();
node tmp;
queue <node> q;
for (int i = 0; i < len; i++)
{
tmp.y = G[1][i].first;
tmp.fee = G[1][i].second;
v[tmp.y] = min(v[tmp.y], tmp.fee);
q.push(tmp);
}
while (!q.empty())
{
node u = q.front(), w;
q.pop();
len = G[u.y].size();
for (int i = 0; i < len; i++)
{
w.y = G[u.y][i].first;
w.fee = u.fee + G[u.y][i].second;
if (w.fee <= v[w.y])
{
q.push(w);
v[w.y] = w.fee;
}
}
}
}
int main()
{
while (~scanf("%d%d", &n, &m))
{
CLR(v, 0x3f);
G->clear();
int x, y;
ll c;
for (int i = 0; i < m; i++)
{
scanf("%d%d%lld", &x, &y, &c);
if (x > y)
swap(x, y);
G[x].pb(pii(y, c));
G[y].pb(pii(x, c));
}
bfs();
if (v[n] == llINF)
printf("qwb baka\n");
else
printf("%lld\n", v[n]);
}
}
2018年长沙理工大学第十三届程序设计竞赛 E 小木乃伊到我家 【最短路】的更多相关文章
- 2018年长沙理工大学第十三届程序设计竞赛 E小木乃伊到我家(spfa模版)
链接:https://www.nowcoder.com/acm/contest/96/E来源:牛客网 小木乃伊到我家 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他 ...
- H-数学考试 想法题+最新头文件 2018年长沙理工大学第十三届程序设计竞赛
https://www.nowcoder.com/acm/contest/96/H 坑点:INF开太小了... #define _CRT_SECURE_NO_WARNINGS #include< ...
- 2018年长沙理工大学第十三届程序设计竞赛 J杯子
链接:https://www.nowcoder.com/acm/contest/96/J来源:牛客网 杯子 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言655 ...
- 2018年长沙理工大学第十三届程序设计竞赛 H数学考试
链接:https://www.nowcoder.com/acm/contest/96/H来源:牛客网 数学考试 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言6 ...
- 2018年长沙理工大学第十三届程序设计竞赛 Dzzq的离散数学教室1
Dzzq的离散数学教室1 链接:https://www.nowcoder.com/acm/contest/96/D来源:牛客网 zzq的离散数学教室1 时间限制:C/C++ 1秒,其他语言2秒 空间限 ...
- 2018年长沙理工大学第十三届程序设计竞赛 G 逃离迷宫 【BFS】
链接:https://www.nowcoder.com/acm/contest/96/G 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536 ...
- 2018年长沙理工大学第十三届程序设计竞赛 C 取手机 【概率】
链接:https://www.nowcoder.com/acm/contest/96/C 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536 ...
- 2018年长沙理工大学第十三届程序设计竞赛 I 连续区间的最大公约数
连续区间的最大公约数 思路:参照BZOJ 4488: [Jsoi2015]最大公约数脑补出的一个\(map\)套\(vector\)的写法,写起来比线段树短,运行时间比线段树快. 代码: #pragm ...
- 哈尔滨理工大学第七届程序设计竞赛初赛(BFS多队列顺序)
哈尔滨理工大学第七届程序设计竞赛初赛https://www.nowcoder.com/acm/contest/28#question D题wa了半天....(真真正正的半天) 其实D题本来就是一个简单 ...
随机推荐
- Dephi泛型generic的应用
Dephi泛型generic的应用 泛型在C++, C#中已有广泛应用,Delphi自2009版本也引入泛型,典型的应用如TList,TDictionary.如果你熟悉C#,其用法十分类似. 比如 ...
- 2010年imac从移动硬盘启动Win10
虽然是个程序员,但也爱折腾. 原WIN10不想折腾,虚拟机折腾大点的软件太卡,不能完全发挥硬件水平. 原材料(硬件):2010年imac一台,80G移动硬盘一块(个人组装,硬盘盒+3.5寸IDE硬盘) ...
- laravel数据库——迁移
1.简介 迁移就像数据库的版本控制,允许团队简单轻松的编辑并共享应用的数据库表结构,迁移通常和Laravel的结构构建器结对从而可以很容易地构建应用的数据库表结构. Laravel的Schema门面提 ...
- 前言和第一章.NET的体系结构
前言 COM:组件对象模型(Component Object Model COM)源自对象链接和嵌入(Object Linking and Embedding )OLE. DCOM:(Distribu ...
- 机器学习2—K近邻算法学习笔记
Python3.6.3下修改代码中def classify0(inX,dataSet,labels,k)函数的classCount.iteritems()为classCount.items(),另外p ...
- busybox下inittab中runlevel解析
Order of scripts run in /etc/rc?.d ================================== 0. Overview. All scripts execu ...
- Apache配置压缩优化时报错——undefined symbol: inflateEnd
Apache配置压缩优化时报错——undefined symbol: inflateEnd 环境:CentOS 6.4 软件版本:httpd-2.4.6 apr-1.4.8 apr-util-1.5. ...
- SetTimer时间间隔的问题
1.用WM_TIMER来设置定时器 SetTimer函数的原型 UINT_PTR SetTimer( HWND hWnd, // 窗体句柄 UINT_PT ...
- python获取shell输出(转)
From:http://www.cnblogs.com/snow-backup/p/5035792.html python中获取shell命令输出的方法: 1. import subproces ...
- 解决ubuntukylin下各种终端字母重叠的方案
ubuntukylin14.04什么都挺好定符合中国人的使用习惯的,可是就是终端字母重叠的问题特别严重;(事实上ubuntu14.04也存在这个问题) 导致非常多非常好用的终端都使用不了,像guake ...