bzoj4264
哈希
cf原题。。。没见过的话真想不出来
将邻接表排序哈希,判断是否相同,但是会漏掉两点相邻的情况,于是再把自己加入自己的邻接表,然后再哈希判断。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = ;
vector<int> G[N];
int n, m;
ll ans;
map<ll, ll> mp;
int main()
{
scanf("%d%d", &n, &m);
for(int i = ; i <= m; ++i)
{
int u, v;
scanf("%d%d", &u, &v);
G[u].push_back(v);
G[v].push_back(u);
}
for(int i = ; i <= n; ++i)
{
sort(G[i].begin(), G[i].end());
G[i].erase(unique(G[i].begin(), G[i].end()), G[i].end());
ll Hash = ;
for(int j = ; j < G[i].size(); ++j)
Hash = Hash * 1234567ll + G[i][j];
++mp[Hash];
}
for(int i = ; i <= n; ++i)
{
G[i].push_back(i);
sort(G[i].begin(), G[i].end());
G[i].erase(unique(G[i].begin(), G[i].end()), G[i].end());
ll Hash = ;
for(int j = ; j < G[i].size(); ++j)
Hash = Hash * 1234567ll + G[i][j];
++mp[Hash];
}
for(map<ll, ll> :: iterator it = mp.begin(); it != mp.end(); ++it)
ans += (it -> second) * (it -> second - 1ll) / 2ll;
printf("%lld\n", ans);
return ;
}
bzoj4264的更多相关文章
- 【bzoj4264】小C找朋友
题解 $a$和$b$是好*友说明除了这两个人以外的邻接集合相同: 做两次$hash$,分别都处理和$a$相邻的点排序$hash$,①$a$要算进$a$的相邻集合,②$a$不算进: 当两个人不是好*友, ...
- 【BZOJ4264】小C找朋友 随机化
[BZOJ4264]小C找朋友 Description 幼儿园里有N个小C,两个小C之间可能是朋友也可能不是.所有小C之间的朋友关系构成了一个无向图,这个无向图中有M条边. 园长ATM发现对于两个(不 ...
- bzoj4264: 小C找朋友
hash大法好 #include <iostream> #include <cstdio> #include <cstring> #include <cmat ...
- 「bzoj4264 小C找朋友」
权限题 就是一个集合\(hash\) 集合\(hash\)可以用于判断两个集合是否相等,具体做法就是给每个随机一个值,之后异或起来就是可以了 这个题就是这样,处理出每个点直接相连的点集的\(hash\ ...
- 刷题总结——小c找朋友(bzoj4264 集合hash)
题目: Description 幼儿园里有N个小C,两个小C之间可能是朋友也可能不是.所有小C之间的朋友关系构成了一个无向图,这个无向图中有M条边. 园长ATM发现对于两个(不同的)小Ci和j,如果其 ...
随机推荐
- ArcGIS:Hello World Maps
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout ...
- Volume 1. String(uva)
10361 - Automatic Poetry #include <iostream> #include <string> #include <cstdio> # ...
- PHP:POST OR GET 请求
文章来源:http://www.cnblogs.com/hello-tl/p/7685216.html /** * 模拟提交参数,支持https提交 可用于各类api请求 * @param strin ...
- tomcat idea 报权限错误
出现的错误提示如下: 下午9:11:27 All files are up-to-date下午9:11:27 All files are up-to-date下午9:11:27 Error runni ...
- 将文件大小kb转换成M
得到文件的大小的一般是直接到得到的是文件的字节大小,也就是kb,我们有的时候需要做单位换算成B或者M, 下面方法只是换成M,没有到G, 有更好的方法,请随时沟通,以便交流学习,谢谢. public s ...
- C51 动态数码管 个人笔记
8段led管构成一个数字. 开发板上共有8个数字. 每个数字有一个使能端(段选引脚) 每个数字的位选端(选择8段led管哪些亮,即构成什么图案)并联在一起 轮流点亮不同数字,速度很快,视觉暂留,从而形 ...
- ajax一个很好的加载效果
推荐一个常用的jquery加载效果插件: 要引入这个插件的css和js: <link href="<%=path %>/css/showLoading.css" ...
- P1072 Hankson的趣味题
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #inclu ...
- [USACO12FEB]附近的牛Nearby Cows
题目描述 Farmer John has noticed that his cows often move between nearby fields. Taking this into accoun ...
- nyoj_308_Substring_201405091611
Substring 时间限制:1000 ms | 内存限制:65535 KB 难度:1 描述 You are given a string input. You are to ...