「bzoj4264 小C找朋友」
2024-08-27 17:06:49
就是一个集合\(hash\)
集合\(hash\)可以用于判断两个集合是否相等,具体做法就是给每个随机一个值,之后异或起来就是可以了
这个题就是这样,处理出每个点直接相连的点集的\(hash\)值,之后判断一下有多少对\(hash\)值相等就好了
在考虑一下每条边就做完了
代码
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<ctime>
#include<map>
#define maxn 1000005
#define re register
#define LL unsigned long long
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
inline int read() {
int x=0;char c=getchar();while(c<'0'||c>'9') c=getchar();
while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+c-48,c=getchar();return x;
}
int u[maxn],v[maxn];
int n,m;
LL a[maxn],s[maxn];
std::map<LL,int> ma;
int main()
{
n=read(),m=read();
srand(time(0));
for(re int i=1;i<=n;i++) a[i]=((LL)(((LL)rand()<<15ll)*((LL)rand()<<12ll))^(LL)rand());
for(re int i=1;i<=m;i++) u[i]=read(),v[i]=read(),s[u[i]]^=a[v[i]],s[v[i]]^=a[u[i]];
LL ans=0;
for(re int i=1;i<=n;i++) ans+=ma[s[i]],ma[s[i]]++;
for(re int i=1;i<=m;i++) if((s[u[i]]^a[v[i]])==(s[v[i]]^a[u[i]])) ans++;
printf("%lld\n",ans);
return 0;
}
最新文章
- C#中的WebBrowser控件的使用
- 自动化测试 using System.Windows.Automation;
- (Hibernate进阶)Hibernate映射——一对多关联映射(七)
- 【转】Unity中的协同程序-使用Promise进行封装(一)
- ✡ leetcode 159. Longest Substring with At Most Two Distinct Characters 求两个字母组成的最大子串长度 --------- java
- 【Android】EventBus 源码解析
- 【POJ】A New Stone Game(博弈论)
- 【转帖】.Net中C#的DllImport的用法
- posix第二篇-----linux 锁机制
- storm kafkaSpout 踩坑问题记录! offset问题!
- ansible批量管理软件部署及剧本
- 轻量Pythonweb - flask+jinja2
- redis搭建主从复用-读写分离
- 【Linux】-NO.5.Linux.1.CentOS.1.001-【CentOS7 Foundation Configuration】-
- python os.path.dirname()
- 关于mysql中information_schema.tables
- NYOJ 36 LCS(最长公共子序列)
- bzoj2733: [HNOI2012]永无乡 线段树合并
- BZOJ3782 上学路线 【dp + Lucas + CRT】
- TOSCA自动化测试工具--Convert to Template