【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. iOS上线check_list

    iOS 上线前 check_list 类型 序号 检查项 结果(pass/no) 安装 卸载 1 非越狱环境下的安装.卸载 2 越狱环境下的安装.卸载 3 安装文件检查,无泄漏用户信息的隐患 4 卸载 ...

  2. sysbench0.5安装介绍

    sysbench是一个模块化的.跨平台.多线程基准测试工具,主要用于评估测试各种不同系统参数下的数据库负载情况,sysbench支持MySQL.PostgreSQL.Oracle数据库OLTP测试.它 ...

  3. windows 操作系统种类

    @hcy 敬请访问:http://blog.sina.com.cn/iihcy Microsoft公司从1983年开始研制Windows系统,最初的研制目标是在MS-DOS的基础上提供一个多任务的图形 ...

  4. maven打包错误:java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test

    Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.118 sec <<< FAILURE! - in ...

  5. 47.Number of Islands(岛的数量)

    Level:   Medium 题目描述: Given a 2d grid map of '1's (land) and '0's (water), count the number of islan ...

  6. 2890: C--去掉+86

    2890: C--去掉+86 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 210  Solved: 91[Submit][Status][Web Bo ...

  7. 用函数创建对象、类创建对象,以及使用prototype的好处

    用函数创建对象 var CheckObject = function(){}; CheckObject.checkName = function(){ // 检验姓名 }; CheckObject.c ...

  8. ES6新增Map、Set和iterable

    Map需要一个二维数组 var test_map = new Map(["mians",99],["regink",88]) test_map.get(&quo ...

  9. python基础面试题整理---从零开始 每天十题(04)

    一.Q:如何用Python来进行查询和替换一个文本字符串? A:可以使用sub()方法来进行查询和替换,sub方法的格式为:sub(replacement, string[, count=0]) re ...

  10. DNA fingerprinting|haplotpe|frequency of polymorphism|限制性标记的多态性

    5.4利用RFLP和SNP绘制遗传图 因为限制性标记可以确定那个分子水平上的突变(即已知基因座),但是无法和蛋白质功能相联系.所以我们采用限制性标记的多态性,即该限制酶识别的位点若发生突变,则大概率在 ...