赛前没啥时间好好解释了,还有三天2019CSP,大家加油啊!!!

ヾ(◍°∇°◍)ノ゙

背掉它就好啦!!!

我觉得我这一版打得还行就放上来了

#include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
#include<cmath>
#include<vector>
using namespace std;
int n,m,s;
int dis[],first[];
inline void read(int &x)
{
char c=getchar();
int flag=; x=;
while (c<''||c>'')
{
if (c=='-') flag=-;
c=getchar();
}
while (c>=''&&c<='')
{
x=x*+c-'';
c=getchar();
}
x*=flag;
}
struct edge
{
int next,to,v;
edge()
{
}
edge(int a,int b,int c)
{
next=a; to=b; v=c;
}
}E[];
struct heap
{
int to,v;
heap()
{
}
heap(int a,int b)
{
to=a; v=b;
}
};
priority_queue<heap> h;
inline bool operator < (const heap &a,const heap &b)
{
return a.v>b.v;
}
int tot;
void add_to_edge(int a,int b,int c)
{
E[++tot]=edge(first[a],b,c);
first[a]=tot;
}
void add_to_heap(int p)
{
for (int i=first[p]; i; i=E[i].next)
{
if (dis[E[i].to]==-)
h.push(heap(E[i].to,dis[p]+E[i].v));
}
}
void dijkstra(int s)
{
while (!h.empty())
{
h.pop();
}
memset(dis,-,sizeof(dis));
dis[s]=;
add_to_heap(s);
while (!h.empty())
{
if (dis[h.top().to]!=-)
{
h.pop();
continue;
}
int p=h.top().to;
dis[p]=h.top().v;
h.pop();
add_to_heap(p);
}
}
int main()
{
read(n); read(m); read(s);
for (int i=; i<=m; i++)
{
int x,y,z;
read(x); read(y); read(z);
add_to_edge(x,y,z);
}
dijkstra(s);
for (int i=; i<=n; i++)
cout<<dis[i]<<" ";
return ;
}

2019CSP-S    RP+++++

最新文章

  1. js中关于原型的几个方法
  2. 如何将word中上下两行文字对齐?
  3. Java 的zip压缩和解压缩
  4. BZOJ3362 [Usaco2004 Feb]Navigation Nightmare 导航噩梦
  5. jQuery中下拉select、复选checkbox、单选radio的操作代码
  6. 《用Java写一个通用的服务器程序》01 综述
  7. JVM 性能调优监控工具
  8. logistic逻辑回归公式推导及R语言实现
  9. iOS UINavigationController Class Translation
  10. Keepalived+Nginx实现高可用Web负载均衡
  11. 表达式目录树(Expression)
  12. IIC时序和24C02读写字节时序
  13. 利用nginx搭建小型的文件服务器
  14. eclipse去掉所有断点 恢复到默认窗口
  15. 1.浅谈CLR
  16. 2015年蓝桥杯省赛A组c++第3题
  17. win10上安装keras
  18. operator模块常见方法介绍
  19. IE6,7,8 CSS HACK
  20. recvfrom WSAEFAULT 10014 的错误记录

热门文章

  1. OpenCascade建模:构建圆环API--BRepPrimAPI_MakeTortus()
  2. Unity3D_(数据)JsonUtility创建和解析Json
  3. 四图3d旋转轮播
  4. SQL中模糊查询的模式匹配
  5. HomeBrew安装MongoDB如何启动
  6. spring-ApplicationContext的事件传播(转)
  7. 二、PHP链接mongodb
  8. typescript 接口 interface
  9. leetcode-easy-others-268 Missing Number
  10. SpringBoot深入了解