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 ...
随机推荐
- 红帽学习笔记[RHCSA] 第四课[用户相关、破解root密码]
第四课 关于Linux 的用户 用户分类: # UID 是用户ID UID 0分配给超级用户(root) UID 1-200 是一系列的 系统用户 静态分配给红帽的系统进程 UID 201 ...
- mysql自动生成my.cnf文件
http://imysql.com/my-cnf-wizard.html
- Python数据结构与算法?
数据结构与算法(Python) 冒泡排序 冒泡排序(英语:Bubble Sort)是一种简单的排序算法.它重复地遍历要排序的数列,一次比较两个元素,如果他们的顺序错误就把他们交换过来.遍历数列的工作是 ...
- 剑指offer-旋转数组的最小数字-数组-python
题目描述 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转.输入一个非递减排序的数组的一个旋转,输出旋转数组的最小元素.例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转 ...
- React -- 3/100 】组件通讯
通讯 | props | prop-types 组件通讯 Props: 组件无论是使用函数声明还是通过 class 声明,都决不能修改自身的 props /* class */ .parent-box ...
- 八、LaTex中的表格
- Django中常用字段
一.Django框架的常用字段 Django ORM 常用字段和参数 常用字段 常用字段 AutoField int自增列,必须填入参数 primary_key=True.当model中如果没有自增列 ...
- lilo.conf - lilo 配置文件
描述 默认情况下,本文件 ( /etc/lilo.conf ) 由引导管理程序 lilo 读取 (参考 lilo(8)). 它看起来可能象这样: boot = /dev/hda delay = 40 ...
- 常用技术blog
淘宝核心系统团队 http://csrd.aliapp.com/ 淘宝搜索技术博客 http://www.searchtb.com 淘宝量子恒道官方博客 http://blog.linezing.co ...
- CentOS7编译安装MySQL8.0
1.下载mysql8.0.16源码包和cmake源码包 cd /usr/local/srcwget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-b ...