计蒜客 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 问题:对于每个询问的起点终点,求 ...
随机推荐
- 论文笔记:DeepCF
Abstract 推荐系统可以看作用户和物品的匹配问题,不过user以及item两者的语义空间差异太大,直接匹配不太符合实际.主流的改进CF的方法有两类:基于表示学习的CF方法以及基于函数学习的表示方 ...
- java之hibernate之加载策略和抓取策略
1.加载策略:指hibernate查询数据时,采用什么样的方式将数据写入内存.Hibernate中提供了两种方式来加载数据:懒加载和即时加载. 2.懒加载又称延迟加载,指使用hiberante API ...
- 局域网电脑禁止ping通的解决方法
方法1:命令行模式进入服务器后 点击 开始——运行 输入命令:netsh firewall set icmpsetting 8这样就可以在外部ping到服务器了 非常简单实用!同样道理,如果想禁止Pi ...
- Java自学-数组 创建数组
Java 如何创建一个数组 数组是一个固定长度的,包含了相同类型数据的 容器 步骤 1 : 声明数组 int[] a; 声明了一个数组变量. []表示该变量是一个数组 int 表示数组里的每一个元素都 ...
- AS shortcuts
stl => statelessstf => statefulalt+enter, select element => add pading or somethingselect c ...
- Oracle大表改为分区表及表空间切换方案
Oracle大表改为分区表及表空间切换方案 一. 背景 由于之前数据库表和索引放在一个表空间导致表空间数据文件增长太快,文件数量即将达到Oracle表空间的限制,需要对表(没有分 ...
- Spring Data Jpa 复杂查询总结
实体类 @Entity @Table(name = "t_hotel") @Data public class THotel { @Id private int id; priva ...
- requests中构造post请求注意点
构造post请求时需要注意点: 通过requests.post()进行POST请求时,传入报文的参数有两个,一个是data,一个是json. 如果是urlencoded 格式 data=字典如果是js ...
- Nginx 配置文件nginx.conf中文详解
######Nginx配置文件nginx.conf中文详解##### #定义Nginx运行的用户和用户组 user www www; #nginx进程数,建议设置为等于CPU总核心数. worker_ ...
- 嵌入式开发之移植OpenCv可执行程序到arm平台
0. 序言 PC操作系统:Ubuntu 16.04 OpenCv版本:4.0 交叉工具链:arm-linux-gnueabihf,gcc version 5.4.0 目标平台:arm 编译时间:201 ...