计蒜客 39280.Travel-二分+最短路dijkstra-二分过程中保存结果,因为二分完最后的不一定是结果 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest M.) 2019ICPC西安邀请赛现场赛重现赛
There are nn planets in the MOT galaxy, and each planet has a unique number from 1 \sim n1∼n. Each planet is connected to other planets through some transmission channels. There are mm transmission channels in the galaxy. Each transmission channel connects two different planets, and each transmission channel has a length.
The residents of the galaxy complete the interplanetary voyage by spaceship. Each spaceship has a level. The spacecraft can be upgraded several times. It can only be upgraded 11 level each time, and the cost is cc. Each upgrade will increase the transmission distance by dd and the number of transmissions channels by ee to the spacecraft. The spacecraft can only pass through channels that are shorter than or equal to its transmission distance. If the number of transmissions is exhausted, the spacecraft can no longer be used.
Alice initially has a 00-level spacecraft with transmission distance of 00 and transmission number of 00. Alice wants to know how much it costs at least, in order to transfer from planet 11 to planet nn.
Input
Each test file contains a single test case. In each test file:
The first line contains nn, mm, indicating the number of plants and the number of transmission channels
The second line contains cc, dd, ee, representing the cost, the increased transmission distance, and the increased number of transmissions channels of each upgrade, respectively.
Next mm lines, each line contains u,v,wu,v,w, meaning that there is a transmission channel between uu and vv with a length of ww.
(2 \le n\le 10^5, n - 1 \le m \le 10^5,1 \le u,v \le n ,1 \le c,d,e,w \le 10^5)(2≤n≤105,n−1≤m≤105,1≤u,v≤n,1≤c,d,e,w≤105)
(The graph has no self-loop , no repeated edges , and is connected)
Output
Output a line for the minimum cost. Output -1−1 if she can't reach.
样例输入复制
5 7
1 1 1
1 2 1
1 3 5
1 4 1
2 3 2
2 4 5
3 4 3
3 5 5
样例输出复制
5
二分+最短路。
代码:
//M-二分+最短路dijkstra-二分过程中保存结果,因为二分完最后的不一定是结果。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+;
const int inf=0x3f3f3f3f;
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second namespace IO{
char buf[<<],*S,*T;
inline char gc(){
if (S==T){
T=(S=buf)+fread(buf,,<<,stdin);
if (S==T)return EOF;
}
return *S++;
}
inline int read(){
int x; bool f; char c;
for(f=;(c=gc())<''||c>'';f=c=='-');
for(x=c^'';(c=gc())>=''&&c<='';x=(x<<)+(x<<)+(c^''));
return f?-x:x;
}
inline long long readll(){
long long x;bool f;char c;
for(f=;(c=gc())<''||c>'';f=c=='-');
for(x=c^'';(c=gc())>=''&&c<='';x=(x<<)+(x<<)+(c^''));
return f?-x:x;
}
}
using IO::read;
using IO::readll; int n,m;
int c,d,e;
int head[maxn<<],cnt;
int dis[maxn],pathmin,edgemin;
bool vis[maxn];
priority_queue<pii,vector<pii>,greater<pii> > q; struct Edge{
int u,v,w;
}path[maxn]; struct node{
int to,next,w;
}edge[maxn<<]; void init()
{
memset(head,-,sizeof head);
memset(edge,,sizeof edge);
memset(vis,,sizeof vis);
memset(dis,inf,sizeof dis);
cnt=;
} void add(int u,int v,int w)
{
edge[cnt].to=v;
edge[cnt].w=w;
edge[cnt].next=head[u];
head[u]=cnt++;
} void dijkstra(int s)
{
dis[s]=;
q.push(mp(,s));
while(!q.empty()){
int u=q.top().se;q.pop();
vis[u]=true;
for(int i=head[u];~i;i=edge[i].next){
int v=edge[i].to;
int w=edge[i].w;
if(dis[v]>dis[u]+w){
dis[v]=dis[u]+w;
q.push(mp(dis[v],v));
}
}
}
} void solve()
{
pathmin=inf;edgemin=inf;
int l=,r=1e5;
while(l<=r){
int mid=(l+r)>>;
init();
for(int i=;i<=m;i++){
if(path[i].w<=mid){
add(path[i].u,path[i].v,);
add(path[i].v,path[i].u,);
}
}
dijkstra();
if(dis[n]<=mid){
r=mid-;
if(edgemin>mid){
edgemin=mid;
pathmin=dis[n];
}
else if(edgemin==mid){
pathmin=min(pathmin,dis[n]);
}
}
else{
l=mid+;
}
}
} int main()
{
n=read();m=read();
// scanf("%d%d",&n,&m);
c=read();d=read();e=read();
// scanf("%d%d%d",&c,&d,&e);
for(int i=;i<=m;i++){
path[i].u=read();path[i].v=read();path[i].w=read();
// scanf("%d%d%d",&path[i].u,&path[i].v,&path[i].w);
}
solve();//路径的最大边权
edgemin=edgemin/d+(edgemin%d==? :);
pathmin=pathmin/e+(pathmin%e==? :); //路径条数
printf("%lld\n",1ll*max(edgemin,pathmin)*c);
}
*/
/* 5 7
1 1 1
1 2 3
1 3 4
1 4 4
2 3 2
2 4 5
3 4 1
3 5 3 3 /*
//M-HY学长的代码orz
//二分+最短路spfa
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std; typedef long long ll;
const int N = 200010, mod = 1e9+7, M = 300005; ll addCost, addDist, addNum; int n, m, fa[N], head[N], tot2;
pair<ll, pair<int ,int > > e1[M];
struct Edge{ int to, next; ll w; } e[M];
void Init() {
tot2=0;
memset(head, -1, sizeof(head));
}
void Addedge(int u, int v, ll w) {
e[tot2]={v, head[u], w}; head[u]=tot2++;
e[tot2]={u, head[v], w}; head[v]=tot2++;
} queue<int > Q;
bool inQ[N];
ll dis[N];
bool spfa(int mid)
{
memset(inQ, false, sizeof(inQ));
memset(dis, INF, sizeof(dis));
dis[1] = 0;
Q.push(1);
inQ[1] = true;
ll mostDist = addDist * mid;
ll mostNum = addNum * mid;
while (!Q.empty())
{
int u = Q.front(); //cout << u << " " << dis[u] << " ---- \n";
Q.pop();
for (int i = head[u]; i != -1; i = e[i].next)
{
if (e[i].w > mostDist)
continue;
if (dis[e[i].to] > dis[u] + 1)
{
dis[e[i].to] = dis[u] + 1;
if (!inQ[e[i].to])
{
Q.push(e[i].to);
inQ[e[i].to] = true;
}
}
}
inQ[u] = false;
}
return dis[n] != INF && dis[n] <= mostNum;
} int main()
{
scanf("%d %d", &n, &m);
scanf("%lld %lld %lld", &addCost, &addDist, &addNum);
Init();
for (int i = 1; i <= m; ++ i)
{
scanf("%d %d %lld", &e1[i].second.first, &e1[i].second.second, &e1[i].first);
Addedge(e1[i].second.first, e1[i].second.second, e1[i].first);
} //cout << 1111 << endl;
// 二分
int l = 0, r = N, mid, ans = INF;
while (l <= r)
{
mid = (l + r) / 2;
if (spfa(mid))
ans = mid, r = mid -1;
else
l = mid + 1;
//cout << l << " " << r << " " << ans << endl;
}
if (ans == INF)
printf ("-1\n");
else
printf ("%lld\n", addCost * ans); return 0;
}
*/
计蒜客 39280.Travel-二分+最短路dijkstra-二分过程中保存结果,因为二分完最后的不一定是结果 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest M.) 2019ICPC西安邀请赛现场赛重现赛的更多相关文章
- 计蒜客 39272.Tree-树链剖分(点权)+带修改区间异或和 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest E.) 2019ICPC西安邀请赛现场赛重现赛
Tree Ming and Hong are playing a simple game called nim game. They have nn piles of stones numbered ...
- 计蒜客 39279.Swap-打表找规律 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest L.) 2019ICPC西安邀请赛现场赛重现赛
Swap There is a sequence of numbers of length nn, and each number in the sequence is different. Ther ...
- 计蒜客 39270.Angel's Journey-简单的计算几何 ((The 2019 ACM-ICPC China Shannxi Provincial Programming Contest C.) 2019ICPC西安邀请赛现场赛重现赛
Angel's Journey “Miyane!” This day Hana asks Miyako for help again. Hana plays the part of angel on ...
- 计蒜客 39268.Tasks-签到 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest A.) 2019ICPC西安邀请赛现场赛重现赛
Tasks It's too late now, but you still have too much work to do. There are nn tasks on your list. Th ...
- The 2019 ACM-ICPC China Shannxi Provincial Programming Contest (西安邀请赛重现) J. And And And
链接:https://nanti.jisuanke.com/t/39277 思路: 一开始看着很像树分治,就用树分治写了下,发现因为异或操作的特殊性,我们是可以优化树分治中的容斥操作的,不合理的情况只 ...
- 计蒜客T2202 数三角形(提高组2017模拟赛(三)day2T3) LZOJ3878攻略
今天模拟赛考了一道计蒜客NOIP2017模拟赛(三)day2T3的数三角形,原题链接 https://nanti.jisuanke.com/t/T2202 ,LZOJ3878攻略.场上想了很久都没转化 ...
- 2019计蒜客信息学提高组赛前膜你赛 #2(TooYoung,TooSimple,Sometimes Naive
计蒜客\(2019CSP\)比赛第二场 巧妙爆零这场比赛(我连背包都不会了\(QWQ\) \(T1\) \(Too\) \(Young\) 大学选课真的是一件很苦恼的事呢! \(Marco\):&qu ...
- 计蒜客模拟赛5 D2T1 成绩统计
又到了一年一度的新生入学季了,清华和北大的计算机系同学都参加了同一场开学考试(因为两校兄弟情谊深厚嘛,来一场联考还是很正常的). 不幸的是,正当老师要统计大家的成绩时,世界上的所有计算机全部瘫痪了. ...
- [计蒜客] 矿石采集【记搜、Tarjan缩点+期望Dp】
Online Judge:计蒜客信息学3月提高组模拟赛 Label:记搜,TarJan缩点,树状数组,期望Dp 题解 整个题目由毫无关联的两个问题组合成: part1 问题:对于每个询问的起点终点,求 ...
随机推荐
- yii框架里DetailView视图和GridView的区别
1,首先从语义上分析 DetailView是数据视图,用于显示一条记录的数据,相当于网页中的详情页 GridView是网格视图,用于显示数据表里的所有记录,相当于网页里的列表页 2.用法上的区别 首先 ...
- .net Dapper 实践系列(1) ---项目搭建(Layui+Ajax+Dapper+MySQL)
目录 写在前面 一.前期准备 1.在MySQL创建数据库 2.创建项目 3.安装程序包 4.添加插件 5.添加DbOption文件夹 6.添加实体类 写在前面 学习并实践使用Dapper 这个小型的O ...
- Nginx fastcgi_cache权威指南
一.简介 Nginx版本从0.7.48开始,支持了类似Squid的缓存功能.这个缓存是把URL及相关组合当做Key,用Md5算法对Key进行哈希,得到硬盘上对应的哈希目录路径,从而将缓存内容保存在该目 ...
- 报错:failed to get the task for process XXX(解决方案)
引文: iOS真机调试程序,报如下错误信息: 原因: 证书问题,project和targets的证书都必须是开发证书,ADHOC的证书会出现此问题. 解决方案: project和targets的证书使 ...
- Gitlab配置webhooks实现自动化部署
Gitlab 自动化部署 原理介绍 配置gitlab当push动作的时候,访问服务器上的一个链接比如www.shenke.group/hook.php hook.php里面写着一行代码,会让服务器gi ...
- unity shader入门(四):高光
高光反射计算公式(phong模型)Cspecular=(Clight*Mspecular)max(0,v*r)mgloss mgloss为材质的官泽度,也成反射度,控制高光区域亮点有多大 Mspecu ...
- selenium 滚动屏幕操作+上传文件
执行js脚本来滚动屏幕: (x,y)x为0 纵向滚动,y为0横向滚动 负数为向上滚动 driver.execute_script('window.scrollBy(0,250)') 上传文件: 1.导 ...
- springboot整合mybatis及封装curd操作-配置文件
1 配置文件 application.properties #server server.port=8090 server.address=127.0.0.1 server.session.tim ...
- PHP-FPM的知识点
https://blog.csdn.net/resilient/article/details/82420863 这个URL,将php的各种模式与知识点说清楚了. 因为php-fpm默认编译进了php ...
- anyproxy学习4-Linux(Centos)搭建anyproxy环境
前言 anyproxy可以跨平台使用,前面第一篇是搭建在windows机器上,本篇讲如何在linux上搭建anyproxy环境,当然有mac的小伙伴也可以用mac去搭建一个环境. nodejs安装 a ...