Remmarguts‘ Date

2024-08-22 04:04
文章标签 remmarguts date

本文主要是介绍Remmarguts‘ Date,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

题意:给定一个有向图,求起点s到终点t的第k短路的长度

分析:处理每个结点v到终点t的最短路径长度f【v】,做为估价函数,然后在反向图上跑以t为起点的最短路,这里估价函数值等于实际值。允许每个点最多入队k次。终点t第k次出队,对应距离d是第k短路的长度。

代码:

#include<bits/stdc++.h>
using namespace std;
const int N=1010,M=200010;
int h[N],rh[N],to[M],w[M],ne[M],tot;
void add(int h[],int a,int b,int c){to[++tot]=b;w[tot]=c;ne[tot]=h[a],h[a]=tot;
}
int n,m,S,T,K;
int f[N],vis[N],cnt[N];
struct node{int s,v,d; //s排序,v点,d距离bool operator<(const node &x)const{return s>x.s;}
};void dijkstra(){memset(f,0x3f,sizeof f); f[T]=0; priority_queue<pair<int,int>> q;q.push(make_pair(0,T));while(q.size()){pair<int,int> t=q.top(); q.pop();int u=t.second;if(vis[u])continue;vis[u]=true; //第一次出队时最小for(int i=rh[u]; i; i=ne[i]){int v=to[i];if(f[v]>f[u]+w[i]){f[v]=f[u]+w[i]; //估价函数q.push(make_pair(-f[v],v));}}}
}
int aStar(){priority_queue<node> q; //优先队列node a={f[S],S,0}; q.push(a);while(q.size()){node t=q.top(); q.pop();int u=t.v;cnt[u]++; //记录出队次数if(cnt[T]==K) return t.d; //边界for(int i=h[u]; i; i=ne[i]){int v=to[i], d=t.d+w[i];if(cnt[v]<K){node a={d+f[v],v,d};q.push(a);}}}return -1;
}
int main(){scanf("%d%d",&n,&m);for(int i=1; i<=m; i++){int a,b,c;scanf("%d%d%d",&a,&b,&c);add(h,a,b,c); add(rh,b,a,c); //反图}scanf("%d%d%d",&S,&T,&K);if(S==T) K++; //重合点,0是第一条dijkstra();printf("%d\n",aStar());
}

这篇关于Remmarguts‘ Date的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1095187

相关文章

Linux date命令 日期格式化与计算

参考资料 8.4.7 dateコマンド(システムの日付と時刻を表示する)【Linux】dateコマンドで日付フォーマットの変更及び日付計算の方法date コマンド 目录 一. 基本语法1.1 -d 选项1.2 格式化 二. 年月日格式化三. 日计算3.1 一天之前3.2 一天之后 四. 月计算4.1 两个月前的月初4.2 两个月后的月初4.3 指定月份的最后一天4.4 指定月份下个月

el-date-picker年份选择默认值为当前年,并且将获取时间转为年月日格式

<el-date-pickervalue-format="yyyy"v-model="leftQuery.year":disabled="timeArr && timeArr.length != 0 ? true : false"type="year"placeholder="选择年"@change=changeYear:picker-options="pickerOptions"></el-da

【git】Your branch is up-to-date 和 Everything up-to-date

1、git commit 之后,出现 On branch masterYour branch is up-to-date with 'github/master'.nothing to commit, working tree clean 继续 git push之后,出现 Everything up-to-date 2、网上大部分解决办法,都是分支问题,比如 http://blo

Hive - 日期从整形转为Date类型

在建表的时候我们常将日期字段设置为INT类型,将诸如20180601这样的数字值来表示日期,这样在做日期比较等操作时没有问题,但是要进行某些日期计算,就要先转成日期类型才能进行计算了,怎么转换呢? 数据准备 下面在Hive中先建一个表,含有一个INT类型的日期字段,插入两行数据。 create table tb (dt INT);insert into tb values (2018070

Date问题

sql里面的Date继承了util里面的Date 如果要从util转化为sql里面的Date, 方法是这样的 new java.sql.Date(birthday.getTime());

ValueError: could not convert string ‘date‘ to float64 at row 0, column 1.

ValueError:无法将字符串“date”转换为第0行第1列的float64。 解决办法: 通过以下代码检查自己的数据,查找问题,逐一改正。 import csvdef find_blank_or_invalid_cells(file_path):blank_cells = []invalid_cells = []with open(file_path, 'r', newline=

【POJ】2449 Remmarguts' Date【k短路】

题目链接:Remmarguts’ Date k短路模板题,用这题验证了我可持久化左偏树的正确性。 #include <stdio.h>#include <vector>#include <queue>#include <algorithm>using namespace std ;typedef long long LL ;typedef pair < int , int > pii

java Date的常用操作

一. 获取当前系统时间和日期并格式化输出: import java.util.Date; import java.text.SimpleDateFormat; public class NowString { public static void main(String[] args) { SimpleDateFormat df = new SimpleDateFormat("yyyy-M

c++ 计算时间的date类

计算时间的date类 代码: #include<iostream> using namespace std; class Date{ private: int year; int month; int day; public: Date(int y=0,int m=0,int d=0); ~Date(){} Date &operator +(int days); Date &opera

包装类_Date类_日历类_File类_目录树状结构JAVA063-071

来源:http://www.bjsxt.com/ 1、S01E063_01常用类之基本数据类型的包装类(Wrapper Class) (1)Integer:MIN_VALUE,MAX_VALUE, toHexString(int):转为十六进制数 parseInt(Stirng):把字符串按十进制转为int intValue:转为int longValue:转为long (2)包装类