D. Shortest Cycle
A[i]&A[j]!=0连边,
求图中最小环
N>128 时必有3环
其他暴力跑
folyd最小环
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- #define sc(x) scanf("%I64d",&x);
- #define read(A) for(int i=0;i<n;i++) scanf("%I64d",&A[i]);
- ll A[];
- ll B[][];
- ll dis[][];
- ll N;
- #define inf 1e18
- ll floyd()
- {
- ll MinCost = inf;
- for(int k=; k<=N; k++)
- {
- for(int i=; i<k; i++)
- for(int j=i+; j<k; j++)
- MinCost = min(MinCost,dis[i][j]+B[i][k]+B[k][j]);
- for(int i=; i<=N; i++)
- for(int j=; j<=N; j++)
- dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
- }
- if(MinCost==inf)return -;
- else return MinCost;
- }
- int main()
- {
- // ll N;
- sc(N);
- ll _k=;
- for(int i=; i<=N; i++)
- {
- sc(A[_k]);
- if(A[_k]!=)_k++;
- }
- if(_k>=)
- {
- puts("");
- }
- else
- {
- N=_k-;
- for(int i=; i<=N; i++)
- {
- for(int j=; j<=N; j++)
- {
- if(i!=j&&(A[i]&A[j]))
- {
- B[i][j]=;
- dis[i][j]=;
- }
- else if(i==j)
- {
- B[i][j]=;
- dis[i][j]=;
- }
- else
- {
- B[i][j]=inf;
- dis[i][j]=inf;
- }
- }
- }
- cout<<floyd()<<'\n';
- }
- }
D. Shortest Cycle的更多相关文章
- CF 1206D - Shortest Cycle Floyd求最小环
Shortest Cycle 题意 有n(n <= 100000)个数字,两个数字间取&运算结果大于0的话连一条边.问图中的最小环. 思路 可以发现当非0数的个数很大,比如大于200时, ...
- Codeforces 1206 D - Shortest Cycle
D - Shortest Cycle 思路:n大于某个值肯定有个三元环,否则floyd找最小环. 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) ...
- D. Shortest Cycle(floyd最小环)
D. Shortest Cycle time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- [Codeforces 1205B]Shortest Cycle(最小环)
[Codeforces 1205B]Shortest Cycle(最小环) 题面 给出n个正整数\(a_i\),若\(a_i \& a_j \neq 0\),则连边\((i,j)\)(注意i- ...
- Codeforces Round #580 (Div. 2)-D. Shortest Cycle(思维建图+dfs找最小环)
You are given nn integer numbers a1,a2,…,ana1,a2,…,an. Consider graph on nn nodes, in which nodes ii ...
- 并不对劲的复健训练-CF1205B Shortest Cycle
题目大意 有\(n\)(\(n\leq 10^5\))个数\(a_1,...,a_n\)(\(a\leq 10^{18}\)).有一个图用这个方法生成:若\(a_i\)按位与\(a_j\)不为0,则在 ...
- 【题解】Shortest Cycle
原题链接:CF1205B 题目大意 给定\(n\)个整数\(a_1,a_2,a_3, \dots ,a_n\),若\(i \neq j\)且\(a_i \land a_j \neq 0\),则 ...
- [CF580C]Shortest Cycle(图论,最小环)
Description: 给 \(n\) 个点的图,点有点权 \(a_i\) ,两点之间有边当且仅当 \(a_i\ \text{and}\ a_j \not= 0\),边权为1,求最小环. Solut ...
- @codeforces - 1205B@ Shortest Cycle
目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个长度为 n 的正整数序列 a1, a2, ..., an ...
随机推荐
- 无法在发送 HTTP 标头之后进行重定向
public ActionResult Index2() { Response.Buffer = true; Response.Clear(); return Redirect("/Wech ...
- Double类型的数值 在写入excel时 如何去掉 科学计算法的 后面数值+ E的 情况
Double start = 20190724100000.000; 写入excel时 是 201907E+13 但想要输出的是 20190724100000 这种格式 Java在java.math包 ...
- linux rz上传-sz下载
yum install lrzsz -y rz 上传文件 不能传目录 如果要传目录需要打包成文件再上传 需要往哪里传东西,先进入哪个目录 rz -y 上传覆盖 sz -y 文件名 ...
- python学习之路 目录
python Python基础-1 python由来 字符编码 注释 pyc文件 python变量 导入模块 获取用户输入 流程控制if while python基础-2 编码转换 pycharm 配 ...
- 配置NAT
NAT是将IP数据报文报头中的IP地址转换为另-一个IP地址的过程,主要用于实现内部网络(私有IP地址)访问外部网络(公有IP地址)的功能.NAT有3种类型:静态NAT.动态地址NAT以及网络地址端口 ...
- P1074 靶形数独 dfs+预处理
https://www.luogu.org/problemnew/show/P1074 显然是dfs 而且没有什么剪枝记忆化之类的 但是预处理比较麻烦 我用三个二维数组存状态:visx[x][i]代表 ...
- uboot第二阶段分析1
一. uboot第二阶段初识 1.1. uboot第二阶段应该做什么 a. 概括来讲uboot第一阶段主要就是初始化了SoC内部的一些部件(譬如看门狗.时钟),然后初始化DDR并且完成重定位. b. ...
- pureftp安装
1.下载 #cd /usr/local/src #wget http://download.pureftpd.org/pub/pure-ftpd/releases/pure-ftpd-1.0.36.t ...
- C# List<Object>值拷贝
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Run ...
- 06.Linux系统-GitLab版本控制服务安装部署
官方文档:https://about.gitlab.com/install/#centos-7 1.yum install -y curl policycoreutils-python openssh ...