D. Shortest Cycle】的更多相关文章

Shortest Cycle 题意 有n(n <= 100000)个数字,两个数字间取&运算结果大于0的话连一条边.问图中的最小环. 思路 可以发现当非0数的个数很大,比如大于200时,一定存在长度为3的环. 如果小于200, 我们就用到了Floyd求最小环的技巧. #include <algorithm> #include <iterator> #include <iostream> #include <cstring> #include &…
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 #d…
D. Shortest Cycle time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given nn integer numbers a1,a2,…,ana1,a2,…,an. Consider graph on nn nodes, in which nodes ii, jj (i≠ji≠j) are conne…
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&qu…
[Codeforces 1205B]Shortest Cycle(最小环) 题面 给出n个正整数\(a_i\),若\(a_i \& a_j \neq 0\),则连边\((i,j)\)(注意i->j的边和j->i的边看作一条.问连边完图的最小环长度 \(n \leq 10^5,0 \leq a_i \leq 10^{18}\) 分析 我们按位考虑.显然满足第i位为1的所有数两两之间都有边,构成一个完全图. 统计第i位为1的数,如果第i位为1的数超过2个,就直接输出3(这3个构成一个最小环…
You are given nn integer numbers a1,a2,…,ana1,a2,…,an. Consider graph on nn nodes, in which nodes ii, jj (i≠ji≠j) are connected if and only if, aiaiAND aj≠0aj≠0, where AND denotes the bitwise AND operation. Find the length of the shortest cycle in th…
题目大意 有\(n\)(\(n\leq 10^5\))个数\(a_1,...,a_n\)(\(a\leq 10^{18}\)).有一个图用这个方法生成:若\(a_i\)按位与\(a_j\)不为0,则在\(a_i,a_j\)间连一条无向边.求这个图的最小环,若无环输出-1. 题解 首先发现当有\(i,j,k\in[1,n]\)满足\(a_i,a_j,a_k\)在同一二进制位上为1时,最小环一定为3. 排除掉这种情况后,发现同一二进制位上为1的至多只有两个数,这两个数之间一定连边. 因为\(a\le…
原题链接:CF1205B   题目大意   给定\(n\)个整数\(a_1,a_2,a_3, \dots ,a_n\),若\(i \neq j\)且\(a_i \land a_j \neq 0\),则节点\(i\)和节点\(j\)相连通.求最小环大小.   \(1 \leq n \leq 10^5\),\(0 \leq a_i \leq 10^{18}\).   题解   题目中的\(a_i\)都在long long的范围内,即\(a_i \in [0, 2^{64})\),则根据容斥原理可得,…
Description: 给 \(n\) 个点的图,点有点权 \(a_i\) ,两点之间有边当且仅当 \(a_i\ \text{and}\ a_j \not= 0\),边权为1,求最小环. Solution: 按每一位考虑若当前这一位为 1 的点超过了 2 个,那么答案就为 3 . 否则只会连一条边,于是最多只有 \(60\) 条边,枚举每条边删掉,求最短路 (边权为1,bfs) 即可. #include <iostream> #include <set> #include <…
目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个长度为 n 的正整数序列 a1, a2, ..., an. 考虑建一张 n 个点的图.假如 ai AND aj ≠ 0,则在 i, j 之间连无向边. 求在这张图上的最小环. Input 第一行一个整数 n 表示序列长度 (1≤n≤10^5) 第二行包含 n 个整数 a1,a2,-,an (0≤ai≤10^18). Output 如果图中不含任何环,输出…