【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 ;
}

【CCF】行车路线 改编Dijkstra的更多相关文章

  1. ccf 行车路线

    问题描述 小明和小芳出去乡村玩,小明负责开车,小芳来导航. 小芳将可能的道路分为大道和小道.大道比较好走,每走1公里小明会增加1的疲劳度.小道不好走,如果连续走小道,小明的疲劳值会快速增加,连续走s公 ...

  2. ccf行车路线

    #include<bits/stdc++.h> using namespace std; const long long INF = 1e18; int n,m; struct node{ ...

  3. ccf 201712-4 行车路线(70分)

    ccf 201712-4 行车路线 解题思路: 首先Dijkstra是基于贪心算法的,即每一次作出的选择都具有贪心选择性.此题由于有“如果连续走小道,小明的疲劳值会快速增加,连续走s公里小明会增加s2 ...

  4. ccf 201712-4 行车路线(Python实现)

    一.原题 问题描述 试题编号: 201712-4 试题名称: 行车路线 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 小明和小芳出去乡村玩,小明负责开车,小芳来导航. 小芳将 ...

  5. 【ccf 2017/12/4】行车路线(dijkstra变形)

    问题描述 小明和小芳出去乡村玩,小明负责开车,小芳来导航. 小芳将可能的道路分为大道和小道.大道比较好走,每走1公里小明会增加1的疲劳度.小道不好走,如果连续走小道,小明的疲劳值会快速增加,连续走s公 ...

  6. ccf 201712-4 行车路线(30分超时)

    问题描述 小明和小芳出去乡村玩,小明负责开车,小芳来导航. 小芳将可能的道路分为大道和小道.大道比较好走,每走1公里小明会增加1的疲劳度.小道不好走,如果连续走小道,小明的疲劳值会快速增加,连续走s公 ...

  7. 【CCF CSP】 20171203 行车路线 Java(有问题)80分

    问题描述 小明和小芳出去乡村玩,小明负责开车,小芳来导航. 小芳将可能的道路分为大道和小道.大道比较好走,每走1公里小明会增加1的疲劳度.小道不好走,如果连续走小道,小明的疲劳值会快速增加,连续走s公 ...

  8. 【CCF】地铁修建 改编Dijkstra

    [题意] 给定有n个点,m条边的无向图,没有平行边和自环,求从1到n的路径中,最长段的最小值(最短路不再是路径和,而是所有段中的最大值) [AC] #include<iostream> # ...

  9. 带你找到五一最省的旅游路线【dijkstra算法推导详解】

    前言 五一快到了,小张准备去旅游了! 查了查到各地的机票 因为今年被扣工资扣得很惨,小张手头不是很宽裕,必须精打细算.他想弄清去各个城市的最低开销. [嗯,不用考虑回来的开销.小张准备找警察叔叔说自己 ...

随机推荐

  1. codevs 1313 质因数分解

    时间限制: 1 s  空间限制: 128000 KB  题目等级 : 青铜 Bronze 题目描述 Description 已知正整数 n是两个不同的质数的乘积,试求出较大的那个质数 . 输入描述 I ...

  2. mac重启privoxy命令

    重启命令 brew services restart privoxy

  3. 解决Starting to watch source with Jekyll and Compass. Starting Rack on port 4000

    问题 Starting to watch source with Jekyll and Compass. Starting Rack on port 4000 rake aborted! Errno: ...

  4. SQLite C/C++ 教程

    目录 1安装 2 C/C++ Interface APIs 3连接到数据库 4创建表 5插入操作 6更新操作 7删除操作 安装 在我们开始使用SQLite在C / C++程序,我们需要确保SQLite ...

  5. urllib基础-构造请求对象,设置用户代理User-Agent

    有的网页具有一些反爬机制,如:需要浏览器请求头中的User-Agent.User-Agent类似浏览器的身份证. 程序中不设置User-Agent.默认是Python-urllib/3.5.这样网站就 ...

  6. 661. Image Smoother@python

    Given a 2D integer matrix M representing the gray scale of an image, you need to design a smoother t ...

  7. 分享一个C++与Python开发的中小型通用游戏服务端框架(跨平台,开源,适合MMORPG游戏)

    在开发一款游戏项目时,在立项时我们往往会考虑或者纠结很多,比如: 1,对于开发来说:服务端和客户端应该选择什么语言?用什么协议通信才更效率?协议后期如何维护?Socket是用长连接还是短连接?TCP还 ...

  8. 【Office_Word】Word排版

    文档排版的步骤: step1.先设置正文的样式 step2.再设置各级标题的样式 step3.最后在"多级列表"里设置各级标题编号 [注]最好按照这三步的顺序来排版,否则将会导致正 ...

  9. (3)zabbix用户管理

    登陆zabbix 默认账号:Admin,密码:zabbix,这是一个超级管理员.登陆之后在右下角可以看到“connected as Admin“(中文版:连接为Admin). zabbix组介绍 我们 ...

  10. centos7系统优化

    优化说明: 一.关闭selinux 二.更改为阿里yum源 三.提权dm用户可以使用sudo 四.优化ssh远程登录配置 五.设置中文字符集 六.设置时间同步 七.历史记录数及登录超时环境变量设置 八 ...