【牛客 - 283H】图论一顿套模板(思维转化,Dijkstra)

题干:
 

由于临近广西大学建校90周年校庆,西大开始了喜闻乐见的校园修缮工程!

然后问题出现了,西大内部有许许多多的道路,据统计有N栋楼和M条道路(单向),每条路都有“不整洁度”W,现在校方想知道从S楼到T楼的所有路径中,“不整洁度”乘积最小是多少。

由于答案可能很大,所以你需要将最后的答案109+7取模

输入描述:

 

第一行为四个整数N、M、S、T,意义如上。

第2至第M+1行每行表示一条道路,有三个整数,分别表示每条道路的起点u,终点v和“不整洁度”W。

输入保证没有自环,可能有重边。

其中W一定是2的整数次幂。

输出描述:

 

输出一个整数,表示最小的不整洁度之乘积对109+7取模的结果。

若无解请输出 -1

示例1

输入

复制

4 4 1 3
1 2 8
1 3 65536
2 4 2
4 3 16

输出

复制

256

解题报告:

    把乘法转化成加法就可以跑Dijkstra了。。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 2e5 + 5;
struct Edge {int to;int ne;ll w;
} e[MAX];
struct Point {int o;ll c;Point(){}Point(int o,ll c):o(o),c(c){}friend bool operator <(const Point & a,const Point & b) {return a.c > b.c;}
};
const ll INF = 0x3f3f3f3f3f3f;
const ll mod = 1e9 + 7;
int n,m,s,t;
int tot;
int head[MAX];
ll dis[MAX];
bool vis[MAX];
void add(int x,int y,ll w) {e[++tot].to = y;e[tot].w = w;e[tot].ne = head[x];head[x] = tot;
}
ll qpow(ll a,ll k) {ll res = 1;while(k) {if(k&1) res = (res * a) % mod;k>>=1;a = (a*a)%mod;}return res % mod;
}
void Dijkstra() {for(int i = 1; i<=n; i++) dis[i] = INF;memset(vis,0,sizeof vis);dis[s] = 0;priority_queue<Point> pq;pq.push(Point(s,0));while(!pq.empty()) {Point cur = pq.top();pq.pop(); if(vis[cur.o]) continue;vis[cur.o]=1;for(int i = head[cur.o]; i!=-1; i=e[i].ne) {//if(vis[cur.o]) continue;if(e[i].w + dis[cur.o] < dis[e[i].to]) {dis[e[i].to] = e[i].w + dis[cur.o];pq.push(Point(e[i].to,dis[e[i].to]));}}}}int main()
{ll c;memset(head,-1,sizeof head);cin>>n>>m>>s>>t;for(int i = 1,a,b; i<=m; i++) {scanf("%d%d%lld",&a,&b,&c);ll tmp = (ll)log2(c);add(a,b,tmp);}Dijkstra();if(dis[t] == INF) puts("-1");else printf("%lld\n",qpow(2,dis[t]%mod));return 0 ;}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441133.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

spss相关性分析看结果_spss相关性分析

当我们想要了解变量的相关程度时,就需要用到相关分析,而相关分析也是回归之前很重要的一步,通常用到的方法是pearson方法。 首先解释一下相关系数,相关系数反应的是两个变量之间变化趋势的方向以及程度,其值范围为-1到+1,正值表示正相关,负值表示负相关,绝对值越大表示…

【牛客 - 283F】出装方案(最小费用最大流)

题干&#xff1a; 众所周知&#xff0c;在各种对抗类游戏里装备都是很重要的一环&#xff0c;不同的出装方案会给玩家带来不同的强度。 dalao手里有N件装备&#xff0c;现在dalao要把装备分给N个队友&#xff0c;每个队友只能分一件装备&#xff0c;而每个队友穿上不同的装…

mysql瓶颈分析_网站瓶颈分析—MYSQL性能分析

一、关于慢查询设置和分析查找慢查询参数mysql> show variables like long%;---------------------------| Variable_name | Value |---------------------------| long_query_time | 10.000000 |---------------------------mysql> show variables like slow%;---------…

【CodeForces - 289C】Polo the Penguin and Strings (水题,字符串,思维构造,有坑)

题干&#xff1a; Little penguin Polo adores strings. But most of all he adores strings of length n. One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the strings length e…

【CodeForces - 289D】Polo the Penguin and Houses (带标号的无根树,Cayley定理,Prufer编码)

题干&#xff1a; Little penguin Polo loves his home village. The village has n houses, indexed by integers from 1 to n. Each house has a plaque containing an integer, the i-th house has a plaque containing integer pi (1 ≤ pi ≤ n). Little penguin Po…

离散信号的抽取和内插例题_《数字信号处理》学习指导与题解 2011年版

《数字信号处理》学习指导与题解出版时间&#xff1a;2011年版内容简介《〈数字信号处理〉学习指导与题解》对“数字信号处理”教学大纲要求的所有知识点进行了提纲挈领的阐述&#xff0c;对于教材《数字信号处理》(吴瑛等主编&#xff0c;2009年8月由西安电子科技大学 出版发行…

【CodeForces - 289E 】Polo the Penguin and XOR operation (数学,异或,贪心)

题干&#xff1a; Little penguin Polo likes permutations. But most of all he likes permutations of integers from 0 to n, inclusive. For permutation p  p0, p1, ..., pn, Polo has defined its beauty — number . Expression means applying the operation …

龙果学院mysql分布式集群代码_龙果学院-MySQL大型分布式集群解决方案

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼1 课程概述2 课程背景3 纵观大型网站架构发展&#xff0c;总结持久化部分需要应对的问题4 操作系统安装以及配置5 在CentOS上通过yum安装mysql5.76 mysql初次见面-mysql5.7的用户以及安全策略7 mysql初次见面续-mysql基本操作8 认识…

【SPOJ - TOURS 387】Travelling tours (最小费用最大流,拆点)

题干&#xff1a; In Hanoi, there are N beauty-spots (2 < N < 200), connected by M one-way streets. The length of each street does not exceed 10000. You are the director of a travel agency, and you want to create some tours around the city which sati…

python问题化教学设计_基于IPO的Python教学设计

冯艳茹 陈平摘要&#xff1a;程序设计基础课程是培养大学生解决计算问题的思维和能力的课程&#xff0c;使用Python作为大学生的首门编程语言课程&#xff0c;可操作性强&#xff0c;入门容易&#xff0c;上手快。该文提出了基于IPO的教学设计新思维&#xff0c;使教学活动和教…

【SPOJ - SCITIES】Selfish Cities (二分图最优匹配,最大费用流)

题干&#xff1a; Far, far away there is a world known as Selfishland because of the nature of its inhabitants. Hard times have forced the cities of Selfishland to exchange goods among each other. C1 cities are willing to sell some goods and the other C2 c…

将方孔分段的lisp_AutoLisp编写工程地质剖面图小工具

AutoLisp编写工程地质剖面图小工具朱红雷李健民 (浙江省水利水电勘测设计院杭州 310002)在我院应用的CAD工程地质制图系统中&#xff0c;通常采用的各种高级语言编制的程序&#xff0c;一般是通过编制数据文件&#xff0c;生成CAD图形数据交换文件(一般为*.SCR或*.DXF)达到绘制…

【CodeForces - 922B 】Magic Forest (数学,异或,暴力,水题,三元组问题)

题干&#xff1a; Imp is in a magic forest, where xorangles grow (wut?) A xorangle of order n is such a non-degenerate triangle, that lengths of its sides are integers not exceeding n, and the xor-sum of the lengths is equal to zero. Imp has to count the …

【牛客 -2A】矩阵(二分,字符串哈希)

题干&#xff1a; 给出一个n * m的矩阵。让你从中发现一个最大的正方形。使得这样子的正方形在矩阵中出现了至少两次。输出最大正方形的边长。 输入描述: 第一行两个整数n, m代表矩阵的长和宽&#xff1b; 接下来n行&#xff0c;每行m个字符&#xff08;小写字母&#xff09…

java生产者消费者代码_Java实现Kafka生产者消费者代码实例

Kafka的结构与RabbitMQ类似&#xff0c;消息生产者向Kafka服务器发送消息&#xff0c;Kafka接收消息后&#xff0c;再投递给消费者。生产者的消费会被发送到Topic中&#xff0c;Topic中保存着各类数据&#xff0c;每一条数据都使用键、值进行保存。每一个Topic中都包含一个或多…

java dom创建xml文件_Java 如何使用dom方式读取和创建xml文件

Java 如何使用dom方式读取和创建xml文件发布时间&#xff1a;2020-11-11 17:08:31来源&#xff1a;亿速云阅读&#xff1a;101作者&#xff1a;Leah本篇文章给大家分享的是有关Java 如何使用dom方式读取和创建xml文件&#xff0c;小编觉得挺实用的&#xff0c;因此分享给大家学…

【CodeForces - 304B】Calendar (前缀和,水题)

题干&#xff1a; Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendars scheme of le…

java 刷新jtextarea_Java JTextArea不能实时刷新的问题

相信JTextArea用法都了解吧&#xff0c;JTextArea textArea new JTextArea();生成一块空白的区域&#xff0c; 我的需求就是点击发送邮件按钮后&#xff0c;后台的执行日志能输出到textArea中。但是我点击发送按钮的时候&#xff0c;由于邮件的附件要好久&#xff0c;界面一直…

【CodeForces - 312C】The Closest Pair (思维)

题干&#xff1a; Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Excee…

java request 封装对象_java通过request自动封装复杂对象

参考&#xff1a;Jfinal源码&#xff0c;在上面基础上改的&#xff0c;然后分享出来适用JAVAEE平台[Java]代码/*** 实现深层封装对象的实例 从request封装对象* 举例&#xff1a;* House.class 属性有三个 ID:id 名称&#xff1a;name 门类&#xff1a;Door doorDoor类: id nam…