You have been offered a job in a company developing a large social network. Your first task is connected with searching profiles that most probably belong to the same user.

The social network contains n registered profiles, numbered from 1 to n. Some pairs there are friends (the "friendship" relationship is mutual, that is, if i is friends with j, then j is also friends with i). Let's say that profiles i and j (i ≠ j) are doubles, if for any profile k (k ≠ ik ≠ j) one of the two statements is true: either k is friends with i and j, or k isn't friends with either of them. Also, i and j can be friends or not be friends.

Your task is to count the number of different unordered pairs (i, j), such that the profiles i and j are doubles. Note that the pairs are unordered, that is, pairs (a, b) and (b, a) are considered identical.

Input

The first line contains two space-separated integers n and m (1 ≤ n ≤ 106, 0 ≤ m ≤ 106), — the number of profiles and the number of pairs of friends, correspondingly.

Next m lines contains descriptions of pairs of friends in the format "v u", where v and u (1 ≤ v, u ≤ n, v ≠ u) are numbers of profiles that are friends with each other. It is guaranteed that each unordered pair of friends occurs no more than once and no profile is friends with itself.

Output

Print the single integer — the number of unordered pairs of profiles that are doubles.

Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the %I64d specificator.

Examples

Input
3 3
1 2
2 3
1 3
Output
3
Input
3 0
Output
3
Input
4 1
1 3
Output
2

Note

In the first and second sample any two profiles are doubles.

In the third sample the doubles are pairs of profiles (1, 3) and (2, 4).

题意:给定无向图,问有多少对点对,在不考虑它们之间的连边情况下,满足它们的直接连边的情况相同。

思路:用hash保存每个点的连边情况,然后排序得到hash值,相同的一并处理。

有两类:第一类是点对间有边,那么我们需要向自己加一条边,那么它们的连边情况是相同的。

第二类是点对间无边,直接处理即可。

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define uint unsigned int
using namespace std;
const int maxn=;
const int seed=;
const int seed2=;
uint p[maxn],p2[maxn];long long ans;
pair<uint,uint>h[maxn];
int main()
{
int N,M,u,v;
scanf("%d%d",&N,&M); p[]=; p2[]=;
rep(i,,N) p[i]=p[i-]*seed;
rep(i,,N) p2[i]=p2[i-]*seed2;
rep(i,,N) h[i].first=p[i],h[i].second=p2[i];
rep(i,,M){
scanf("%d%d",&u,&v);
h[u].first+=p[v]; h[v].first+=p[u];
h[u+N].first+=p[v]; h[v+N].first+=p[u];
h[u].second+=p2[v]; h[v].second+=p2[u];
h[u+N].second+=p2[v]; h[v+N].second+=p2[u];
}
sort(h+,h+N+N+);
for(int i=;i<=N+N;i++){
int j=i;
while(j+<=N+N&&h[j+]==h[i]) j++;
ans+=(long long)(j-i+)*(j-i)/;
i=j;
}
printf("%I64d\n",ans);
return ;
}

CodeForces - 154C:Double Profiles (hash+排序)的更多相关文章

  1. Codeforces Round #109 (Div. 2) E. Double Profiles hash

    题目链接: http://codeforces.com/problemset/problem/155/E E. Double Profiles time limit per test 3 second ...

  2. xtu summer individual 2 E - Double Profiles

    Double Profiles Time Limit: 3000ms Memory Limit: 262144KB This problem will be judged on CodeForces. ...

  3. codeforces Round #440 A Search for Pretty Integers【hash/排序】

    A. Search for Pretty Integers [题目链接]:http://codeforces.com/contest/872/problem/A time limit per test ...

  4. sort 树 hash 排序

    STL 中 sort 函数用法简介 做 ACM 题的时候,排序是一种经常要用到的操作.如果每次都自己写个冒泡之类的 O(n^2) 排序,不但程序容易超时,而且浪费宝贵的比赛时间,还很有可能写错. ST ...

  5. [置顶] Codeforces 70D 动态凸包 (极角排序 or 水平序)

    题目链接:http://codeforces.com/problemset/problem/70/D 本题关键:在log(n)的复杂度内判断点在凸包 或 把点插入凸包 判断:平衡树log(n)内选出点 ...

  6. DataTable 中varchar 转换为 Double 后重新 排序。

    DataTable  查询出某个字段为varchar 类型的.不过里面存的为数字,需要进行排序.可是如果直接排序就会不对.因为为varchar类型的,需要转换一下. 方法一: dt.Columns.A ...

  7. ruby中Hash排序

    当values都是整形时,按照Hash的Values排序: h = {'a'=>1,'b'=>2,'c'=>5,'d'=>4} h.sort {|a,b| a[1]<=& ...

  8. Codeforces 484B Maximum Value(排序+二分)

    题目链接: http://codeforces.com/problemset/problem/484/B 题意: 求a[i]%a[j] (a[i]>a[j])的余数的最大值 分析: 要求余数的最 ...

  9. Codeforces 825E Minimal Labels - 拓扑排序 - 贪心

    You are given a directed acyclic graph with n vertices and m edges. There are no self-loops or multi ...

随机推荐

  1. KVM虚拟化虚拟机支持虚拟化

    一.开启的时候需要关闭所有虚拟机: 首先检查 KVM host(宿主机/母机)上的kvm_intel模块是否打开了嵌套虚拟机功能(默认是开启的): 1.modinfo kvm_intel | grep ...

  2. python之路 模块,序列化,迭代器,生成器

    一.模块 1.模块简介 模块是一个包含所有你定义的函数和变量的文件,其后缀名是.py.模块可以被别的程序引入,以使用该模块中的函数等功能.这也是使用python标准库的方法. 类似于函数式编程和面向过 ...

  3. python tkinter组件学习

    http://blog.csdn.net/pfm685757/article/details/50162567

  4. rsh命令配置于使用

    安装环境:一台centos6.10虚拟机,一台centos7.5虚拟机,全部使用root用户登录. 两台机器上都要安装rsh.rsh-server.xinetd包. 两台机器都要关闭防火墙并配置/et ...

  5. Django源码剖析

    一.Django底层剖析之一次请求到响应的整个流程 As we all know,所有的Web应用,其本质上其实就是一个socket服务端,而用户的浏览器就是一个socket客户端 #!/usr/bi ...

  6. 线性代数:A转置乘以A可逆

    如果A的列向量线性无关,则 T(A)*A得到一个可逆的方阵. 假设A是一个kxn的矩阵,那么T(A)*A是一个nxn的方阵:要证明这个方阵可逆,只要证明N(T(A)*A) = 零空间即可. 假设列向量 ...

  7. SQL Server获取数据库的当前连接状态

    SELECT * FROM [Master].[dbo].[SYSPROCESSES] WHERE [DBID]=(SELECT [DBID] FROM [Master].[dbo].[SYSDATA ...

  8. 数据库系统概论学习4-SQL 语句和关系代数(二)单表查询

    4.12 字符匹配 精确查询和模糊查询 在这一节之前,我们学习的查询几乎都是精确查询,这就需要我们明确地知道某些属性的具体值.例如我们需要查询 'Wangxiaoxiao' 同学的信息,就需要在WHE ...

  9. 通过公钥解密密文思路(256bits RSA)

    256bit RSA公钥安全系数极低,只需要几分钟即可破解密文,本文综合其他文章记录了一次解密256bits RSA加密的密文的过程,仅作为备忘. 1.分解公钥,分解出n与e: 1.1使用openss ...

  10. eclipse maven 项目 maven build 无反应

    eclipse maven 项目 使用maven build ,clean 等命令均无反应,控制台无任何输出 1.打开Window --> Preferences --> Java --& ...