博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【LibreOJ】#6354. 「CodePlus 2018 4 月赛」最短路 异或优化建图+Dijkstra
阅读量:6906 次
发布时间:2019-06-27

本文共 1226 字,大约阅读时间需要 4 分钟。

【题目】

【题意】给定n个点,m条带权有向边,任意两个点i和j还可以花费(i xor j)*C到达(C是给定的常数),求A到B的最短距离。\(n \leq 10^5,m \leq 5*10^5\)
【算法】异或优化建图+Dijkstra
正常建边O(n^2),与其考虑特殊边的处理不如考虑优化n^2的建边方案。一个点x到另一个点y的代价是由每个改变的数位得到的,所以枚举所有点x的每个数位j,从x向\(x \ \ xor \ \ 2^j\)连边代价为\(2^j\)
复杂度\(O((m+n \ \ log \ \ n) \ \ log \ \ n)\)

#include
#include
#include
#include
bool isdigit(char c){return c>='0'&&c<='9';}int read(){ int s=0,t=1;char c; while(!isdigit(c=getchar()))if(c=='-')t=-1; do{s=s*10+c-'0';}while(isdigit(c=getchar())); return s*t;}using namespace std;const int maxn=100010,maxm=500010;int tot,first[maxn],n,m,C,d[maxn];struct edge{int v,w,from;}e[maxm+maxn*20];void insert(int u,int v,int w){tot++;e[tot].v=v;e[tot].w=w;e[tot].from=first[u];first[u]=tot;}struct cyc{ int d,id; bool operator < (const cyc &a)const{ return d>a.d; }};priority_queue
Q;void dijkstra(int S){ memset(d,0x3f,sizeof(d)); d[S]=0;Q.push((cyc){0,S}); while(!Q.empty()){ cyc X=Q.top();Q.pop(); int D=X.d,x=X.id; if(D!=d[x])continue; for(int i=first[x];i;i=e[i].from)if(d[x]+e[i].w

转载于:https://www.cnblogs.com/onioncyc/p/9082745.html

你可能感兴趣的文章
php实现一个单链表
查看>>
向Combox控件中添加数据
查看>>
【ADO.NET】5、手机归属地查询( winfrom )
查看>>
老司机教你如何正确地在大陆安装 BlackArch
查看>>
大型网站架构系列:负载均衡详解(3)(转)
查看>>
bzoj 2152 聪聪可可
查看>>
最大流
查看>>
bzoj千题计划308:bzoj4589: Hard Nim(倍增FWT+生成函数)
查看>>
react入门安装
查看>>
koala之学习(less编译)
查看>>
Java基础学习总结——Java对象的序列化和反序列化
查看>>
spring的事务管理有几种方式实现 (转自:http://blog.csdn.net/bopzhou/article/details/7094108)...
查看>>
ngx_echo_module
查看>>
HDU5322 Hope
查看>>
回车事件
查看>>
Linux实战教学笔记17:精简shell基础
查看>>
U盘安装windos10,报错“Windows 无法打开所需的文件 Sources\install.wim”
查看>>
ios NSThred多线程简单使用
查看>>
java基础总结
查看>>
LoadAssetAtPath 与 Load 的区别
查看>>