首页 技术 正文
技术 2022年11月16日
0 收藏 487 点赞 3,797 浏览 1735 个字

Shortest Cycle

题意

有n(n <= 100000)个数字,两个数字间取&运算结果大于0的话连一条边。问图中的最小环。

思路

可以发现当非0数的个数很大,比如大于200时,一定存在长度为3的环。

如果小于200, 我们就用到了Floyd求最小环的技巧。

#include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <cassert>
#include <unordered_map>
// #include<bits/extc++.h>
// using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define fi first
#define se second
#define debug(x) cerr<<#x << " := " << x << endl;
#define bug cerr<<"-----------------------"<<endl;
#define FOR(a, b, c) for(int a = b; a <= c; ++ a) 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f;
const int mod = ;template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
}
/**********showtime************/
const int maxn = 2e5+;
ll a[maxn];
int cnt[];
ll ans;
ll dp[][], g[][];
vector<ll>b;
int main(){
int n;
scanf("%d", &n);
int cnt = ;
for(int i=; i<=n; i++){
scanf("%lld", &a[i]);
if(a[i] == ) cnt++;
else b.pb(a[i]);
}
if(n - cnt > ) puts("");
else {
int n = b.size();
for(int i=; i<=n; i++){
for(int j=; j<=n; j++) {
if(i == j) dp[i][j] = ,g[i][j] = ;
else dp[i][j] = dp[j][i] = inf, g[i][j] = inf;
}
}
for(int i=; i<n; i++) {
for(int j=i+; j<n; j++) {
if((b[i] & b[j]) > ) {
dp[i+][j+] = ;
dp[j+][i+] = ;
g[i+][j+] = ;
g[j+][i+] = ;
}
}
}
ans = inf;
for(int k=; k<=n; k++) {
for(int i=; i<k; i++) {
for(int j=i+; j<k; j++) {
ans = min(ans, dp[i][j] + g[k][i] + g[k][j]);
}
}
for(int i=; i<=n; i++) {
for(int j=; j<=n; j++) {
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
}
}
}
if(ans == inf) puts("-1");
else printf("%lld\n", ans);
}
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,110
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,584
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,431
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,202
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,837
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,920