【AC】

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue> using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int maxn=5e2+;
const int maxm=1e5+;
int n,m;
struct edge{
int t;
int to;
int nxt;
ll w;
}e[*maxm];
struct node{
int id;
ll d;
ll fa;
node(int _id,ll _d,ll _fa):id(_id),d(_d),fa(_fa){}
bool operator < (const node& a) const{
if(d!=a.d) return d>a.d;
return fa>a.fa;
}
};
int head[maxn];
int tot;
ll dis[maxn];
ll fa[maxn];
bool vis[maxn];
void init(){
memset(head,-,sizeof(head));
tot=;
}
void add(int t,int u,int v,ll w){
e[tot].t=t;
e[tot].to=v;
e[tot].w=w;
e[tot].nxt=head[u];
head[u]=tot++;
}
ll dijkstra(int s){
memset(dis,inf,sizeof(dis));
memset(fa,inf,sizeof(fa));
memset(vis,false,sizeof(vis));
dis[s]=,fa[s]=;
priority_queue<node> Q;
Q.push(node(s,dis[s],fa[s]));
while(!Q.empty()){
node q=Q.top();
Q.pop();
int u=q.id;
if(vis[u]) continue;
vis[u]=true;
for(int i=head[u];i!=-;i=e[i].nxt){
int t=e[i].t;
int v=e[i].to;
ll w=e[i].w;
if(t==){
if(dis[u]+w<=dis[v]){
dis[v]=dis[u]+w;
fa[v]=;
Q.push(node(v,dis[v],fa[v]));
}
}else{
ll tmp=(fa[u]+w)*(fa[u]+w)+dis[u]-fa[u]*fa[u];
if(tmp<dis[v]){
dis[v]=tmp;
fa[v]=fa[u]+w;
Q.push(node(v,dis[v],fa[v]));
}else if(tmp==dis[v]){
if(fa[u]+w<fa[v]){
fa[v]=fa[u]+w;
Q.push(node(v,dis[v],fa[v]));
}
}
}
}
}
return dis[n];
}
int main(){
while(~scanf("%d%d",&n,&m)){
init();
int t,u,v;
ll w;
for(int i=;i<=m;i++){
scanf("%d%d%d%lld",&t,&u,&v,&w);
add(t,u,v,w);
add(t,v,u,w);
}
ll ans=dijkstra();
printf("%lld\n",ans);
}
return ;
}

最新文章

  1. IOS开发基础知识--碎片50
  2. Sokcet方式请求HTTP/HTTPS的封装类HttpHelper
  3. MAC 设置环境变量path的几种方法
  4. nosql数据库学习
  5. LInux配置jdk(mac和windows)
  6. EasyUI——常见用法总结
  7. hive查看建表语句
  8. 实例详解 DB2 排序监控和调优
  9. 内部类访问局部变量的时候,为什么变量必须加上final修饰
  10. hdoj 1231 最大连续子序列
  11. 自制单片机之十六……将文字或图形转成LCD上使用的C51字模数据
  12. JSP自定义标签——简单标签(2)
  13. 20140719中国互联网公司市值排名TOP20
  14. 保存和恢复 Android Fragment 的状态
  15. JS异步加载的三种方案
  16. 通过浏览器F12开发工具快速获取别的网站前端代码的方法
  17. spring初始化bean时执行某些方法完成特定的初始化操作
  18. Cartographer源码阅读(4):Node和MapBuilder对象2
  19. git 新建工程
  20. Jenkins + testNg + maven 项目持续集成

热门文章

  1. ios UnitTest 学习笔记1
  2. 遍历PspCidTable枚举进程
  3. 运行powershell 脚本 在此系统上禁止运行脚本
  4. Sublime Text3括号配对与代码包围效果BracketHighlighter
  5. windows中安装模拟器后修改模拟器中的hosts方法
  6. websocket 入门
  7. 如何关闭OSX 10.11 SIP (System Integrity Protection)
  8. python之道04
  9. Core Animation演示
  10. C语言数据类型_02