首页 > 隐匿社交网络
头像 Gnomeshgh112
发表于 2025-03-28 14:39:55
因为权重在18次方以内,变为2进制不超过64位,最多情况下只有64个网络,从左到右针对每一个数字,可以通过遍历网络,来看自己是否属于某一个网络。网络的标志为:网络内各个数字的或,如果这个位置上为1,说明网络内至少存在一个用户,在这个位置上为1。判断一个数字是否属于一个网络:这个数字和网络标识与,如果 展开全文
头像 lhp_zml
发表于 2025-03-09 16:38:12
按位与操作,同时是 1 才会是 1,数据两两做与操作会超时。 所以可以先考虑吧每个数转为其二进制形式存储起来,一个数的二进制形式存一行,n个数,总共n行。时间复杂度为:nlogn 遍历每一列,把是 1 的每一行下标用并查集合并,因为它们做与操作结果会大于等于 1 并查集,p[N], si[N],p 展开全文
头像 TQ988
发表于 2025-07-08 18:41:59
import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Main { public static int merge(Map<Long, Integer> m 展开全文
头像 11155454
发表于 2025-03-30 00:37:51
#include <bits/stdc++.h> using namespace std; #define ll unsigned long long #define fo(i,a,b) for(int i=a;i<b;i++) vector<ll>a(64); i 展开全文
头像 牛客856751393号
发表于 2025-03-11 22:24:20
超时了 def find(a): if p[a] != a: p[a] = find(p[a]) # 查找父节点 return p[a] def merge(a, b): # 合并两个集合 pa = find(a) pb = fi 展开全文
头像 Goldminer
发表于 2025-04-23 23:08:28
#include <bits/stdc++.h> using namespace std; #define ll unsigned long long #define fo(i,a,b) for(int i=a;i<b;i++) // 定义一个循环宏,用于简化循环代码 vecto 展开全文
头像 牛客907437933号
发表于 2025-04-01 22:21:36
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner sc = new S 展开全文
头像 番禺小韭菜
发表于 2025-03-05 20:00:07
#include <any> #include <iostream> #include <vector> using namespace std; class Total_set { public: vector<int> parent; 展开全文
头像 Whhhhhhhhhhhhhh
发表于 2025-03-30 21:08:50
#include <iostream> #include <vector> using namespace std; #define int long long const int N = 100010; int w[N],s[N]; int fa[N]; int find( 展开全文
头像 Nanssu
发表于 2025-03-13 19:11:53
#include <algorithm> #include <climits> #include <iostream> #include <bits/stdc++.h> #include <iterator> #include <se 展开全文