Codeforces 1206 D - Shortest Cycle
D - Shortest Cycle
思路:n大于某个值肯定有个三元环,否则floyd找最小环。
代码:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define double long double
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb emplace_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define pdd pair<double, double>
#define mem(a, b) memset(a, b, sizeof(a))
#define debug(x) cerr << #x << " = " << x << "\n";
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//head
const int N = 1e5 + 5;
const int INF = 1e8;
LL a[N];
int mp[205][205], dis[205][205];
int n, cnt;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]), cnt += a[i]==0;
sort(a+1, a+1+n, greater<LL>());
n -= cnt;
if(n >= 200) {
printf("3\n");
return 0;
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
if(i == j) continue;
if(((a[i]&a[j]) != 0)) mp[i][j] = dis[i][j] = 1;
else mp[i][j] = dis[i][j] = INF;
}
}
int ans = INF;
for (int k = 1; k <= n; ++k) {
for (int i = 1; i < k; ++i) {
for(int j = i+1; j < k; ++j) {
ans = min(ans, dis[i][j]+mp[j][k]+mp[k][i]);
}
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
dis[i][j] = min(dis[i][j], dis[i][k]+dis[k][j]);
}
}
}
if(ans == INF) printf("-1");
else printf("%d\n", ans);
return 0;
}
Codeforces 1206 D - Shortest Cycle的更多相关文章
- [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 ...
- codeforces 1051F The Shortest Statement
题目链接:codeforces 1051F The Shortest Statement 题意:\(q\)组询问,求任意两点之间的最短路,图满足\(m-n\leq 20\) 分析:一开始看这道题:fl ...
- CF 1206D - Shortest Cycle Floyd求最小环
Shortest Cycle 题意 有n(n <= 100000)个数字,两个数字间取&运算结果大于0的话连一条边.问图中的最小环. 思路 可以发现当非0数的个数很大,比如大于200时, ...
- D. Shortest Cycle(floyd最小环)
D. Shortest Cycle time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- D. Shortest Cycle
D. Shortest Cycle A[i]&A[j]!=0连边, 求图中最小环 N>128 时必有3环 其他暴力跑 folyd最小环 #include<bits/stdc++.h ...
- @codeforces - 1205B@ Shortest Cycle
目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个长度为 n 的正整数序列 a1, a2, ..., an ...
- codeforce D. Shortest Cycle(floyd求最短环)
题目链接:http://codeforces.com/contest/1206/problem/D 给n个点,如果点a[ i ] &a[ j ] 不为0,则点a[ i ] 和 a[ j ] 直 ...
- Codeforces 932.C Permutation Cycle
C. Permutation Cycle time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
随机推荐
- pt-kill MySQL会话杀灭神器
废话不多说,直接上例子: pt-kill --host=127.0.0.1 --user=xxx --password=xxxxxx --port=xxxx --busy-time 10 --matc ...
- 【神经网络与深度学习】【计算机视觉】RCNN- 将CNN引入目标检测的开山之作
转自:https://zhuanlan.zhihu.com/p/23006190?refer=xiaoleimlnote 前面一直在写传统机器学习.从本篇开始写一写 深度学习的内容. 可能需要一定的神 ...
- beyond Compare 30天过期后的处理办法
打开Beyond Compare 4,提示已经超出30天试用期限制,解决方法: 修改C:\Program Files\Beyond Compare 4\BCUnrar.dll,这个文件重命名或者直接删 ...
- P1993 小K的农场(差分约束)
小K的农场 题目描述 小K在MC里面建立很多很多的农场,总共n个,以至于他自己都忘记了每个农场中种植作物的具体数量了,他只记得一些含糊的信息(共m个),以下列三种形式描述: 农场a比农场b至少多种植了 ...
- [WCF] - 使用 bat 批处理文件将 WCF 服务部署为 Windows Service
1. 添加 Windows Service 项目 2. 添加 WCF 项目引用 3. 更新 App.config 配置文件(可以从 WCF的 Web.config 拷贝过来),设置服务地址. 4. 配 ...
- JAVA httpURLConnection curl
// 文件路径 D:\ApacheServer\web_java\HelloWorld\src\com\test\TestHttpCurl.java package com.test; import ...
- CH01基于Ubuntu系统的ZYNQ-7000开发环境的搭建
1.1概述 实验环境: Windows 10 专业版 Vmware workstation 14.1.1 Ubuntu 16.04.3 Xilinx SDx 2017.4 实验内容: 国内Window ...
- CSS实现自适应分隔线的N种方法
分割线是网页中比较常见的一类设计了,比如说知乎的更多回答 这里的自适应是指两边的横线会随着文字的个数和父级的宽度自适应 偷偷的看了一下知乎的实现,很显然是用一块白色背景覆盖的,加一点背景就露馅了 心想 ...
- DG环境恢复同步遇到报错ORA-00353ORA-00334以及ORA-00600[2619], [47745]
问题说明 客户环境主库4节点RAC11.2.0.4,单实例DG环境,DG由于空间不足,导致同步中断,由于DG备库未应用的归档主库都再,本次恢复的方式,是开启dg mrp进程,自动同步追上主库. 以下遇 ...
- shell 学习笔记3-shell变量扩展
一.特殊位置参数变量 1.特殊位置参数变量 在shell中比如:$0.$1.$#,等被称为特殊位置参数变量,当命令行.函数.脚本执行等处传递参数时,就需要使用位置参数变量 参数说明如下: 2.示例$1 ...