Double Profiles

Time Limit: 3000ms
Memory Limit: 262144KB

This problem will be judged on CodeForces. Original ID: 154C
64-bit integer IO format: %I64d      Java class name: (Any)

 

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.

 

Sample Input

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

Hint

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).

 

Source

 
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
LL _hash[maxn],A[maxn],B[maxn];
int main(){
int n,m,x,y,i;
LL ans = ,cnt1 = ,cnt2 = ,pre1 = -,pre2 = -;
_hash[] = ;
scanf("%d %d",&n,&m);
for(i = ; i <= n; i++)
_hash[i] = _hash[i-]*;
for(i = ; i < m; i++){
scanf("%d%d",&x,&y);
A[x] += _hash[y];
A[y] += _hash[x];
}
for(i = ; i <= n; i++)
B[i] += A[i]+_hash[i];
sort(A+,A+n+);
sort(B+,B+n+);
for(i = ; i <= n; i++){
if(A[i] == pre1){
cnt1++;
ans += cnt1;
}else{
cnt1 = ;
pre1 = A[i];
}
if(B[i] == pre2){
cnt2++;
ans += cnt2;
}else{
cnt2 = ;
pre2 = B[i];
}
}
printf("%I64d\n",ans);
return ;
}

xtu summer individual 2 E - Double Profiles的更多相关文章

  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. CodeForces - 154C:Double Profiles (hash+排序)

    You have been offered a job in a company developing a large social network. Your first task is conne ...

  3. xtu summer individual 6 B - Number Busters

    Number Busters Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on CodeForces. ...

  4. xtu summer individual 4 C - Dancing Lessons

    Dancing Lessons Time Limit: 5000ms Memory Limit: 262144KB This problem will be judged on CodeForces. ...

  5. xtu summer individual 3 C.Infinite Maze

    B. Infinite Maze time limit per test  2 seconds memory limit per test  256 megabytes input standard ...

  6. xtu summer individual 2 C - Hometask

    Hometask Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Origin ...

  7. xtu summer individual 1 A - An interesting mobile game

    An interesting mobile game Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on H ...

  8. xtu summer individual 2 D - Colliders

    Colliders Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Origi ...

  9. xtu summer individual 1 C - Design the city

    C - Design the city Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu D ...

随机推荐

  1. 数学 2015百度之星初赛2 HDOJ 5255 魔法因子

    题目传送门 /* 数学:不会写,学习一下这种解题方式:) 思路:设符合条件的数的最高位是h,最低位是l,中间不变的部分为mid,由题意可得到下面的公式(这里对X乘上1e6用a表示,b表示1e6) (h ...

  2. h5-22-地理位置

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  3. Android设计模式——MVP

    一.什么是MVP MVP:全称 Model-View-Presenter. MVP框架由3部分组成:View层负责显示,Presenter层负责逻辑处理,Model层提供数据. View:负责绘制UI ...

  4. 【转】深入理解Android中的SharedPreferences

    SharedPreferences作为Android中数据存储方式的一种,我们经常会用到,它适合用来保存那些少量的数据,特别是键值对数据,比如配置信息,登录信息等.不过要想做到正确使用SharedPr ...

  5. htm 中 <b>和<strong>的区别

    显示上两者没有任何区别,都是粗体<b>:为了加粗而加粗,推荐使用 css font-weight 属性来创建粗体文字.<strong>:为了强调而加粗,表示十分重要.在网页中使 ...

  6. mac自带终端安装完ohmyZsh后显示乱码

    修改描述文件-添加 选择新导入的 Meslo LG M Regular for Powerline

  7. 洛谷 P3178 [HAOI2015]树上操作

    题目描述 有一棵点数为 N 的树,以点 1 为根,且树点有边权.然后有 M 个操作,分为三种:操作 1 :把某个节点 x 的点权增加 a .操作 2 :把某个节点 x 为根的子树中所有点的点权都增加 ...

  8. pycharm激活码 pycharm安装后激活方式 pycharm汉化包安装

    汉化包 下载地址: 链接:http://pan.baidu.com/s/1pL6xWl9 密码:x1fh 将下载好的文件解压:将resources_cn.jar放到安装目录下的lib目录下即可 重启 ...

  9. 配置nginx+tomcat支持websocket

    问题情景:    最近开发新增加一个项目,需要支持https wss协议 访问https://test.aa.com  使用nginx反向代理到后端tomcat web应用 访问https://tes ...

  10. DI:Defect Index(缺陷率)

    DI:Defect Index(缺陷率) 定义:DI值是衡量软件质量的高低的指标之一. 公式:DI= 致命级别的问题个数*10+严重级别的问题个数*3+一般级别的问题个数*1+提示级别的问题个数*0. ...