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. rhel6.5--http练习

    包名 简介 httpd-2.2.15-29.el6_4.x86_64.rpm         http服务的主程序包 httpd-devel-2.2.15-29.el6_4.x86_64.rpm ap ...

  2. Oracle及其相关软件历史版本下载地址

    https://edelivery.oracle.com/osdc/faces/Home.jspx 打开上面这个链接,输入自己或可用的帐号即可. 搜索到自己想要下载的软件后,点击,软件会添加到购物车中 ...

  3. RabbitMQ十:重要方法简述(参数)

    主要方法 前言 经过前面的学习,RabbitMQ 已经拙见有一定认识和了解,今天主要针对我们在前面学习方法进行一次小总结,本篇文章也想在开头写的,但是后来考虑,如果我都把方法都一一列举,我想大家都没很 ...

  4. oracle的Hint

    与优化器模式相关的Hint 1 ALl_ROWS   让优化器启用CBO /*+ all_rows */ 2  first_rows(n)     让优化器启用CBO 模式,而且得到目标sql的执行计 ...

  5. this.$Message.success('提示信息') 少写了一个c 导致报错

    this.$Message.success('提示信息') 少写了一个c 导致报错 而且 $Message 输出还没显示,导致我以为是没有 $Message 对象了,其实全局对象直接调用即可

  6. tmp note

    cat file.txt > /dev/null 2>&1 丢弃错误和标准输出 systemctl isolate multi-user.target 切换回多用户命令行模式 sy ...

  7. GC相关的面试题

    问题:Object的finaliz()方法 的作用是否与C++的析构函数作用相同? --->不同的 1.C++的析构函数调用确定,就是对象离开作用域之后就马上被删除.而java Object的f ...

  8. 全局/局部变量、宏、const、static、extern

    #pragma mark--全局变量和局部变量 根据变量的作用域,变量可以分为: 一.全局变量 1> 定义:在函数外面定义的变量2> 作用域:从定义变量的那一行开始,一直到文件结尾(能被后 ...

  9. iOS之绘制像素到屏幕

    译注:这篇文章虽然比较长,但是里面的内容还是很有价值的. 像素是如何绘制到屏幕上面的?把数据输出到屏幕的方法有很多,通过调用很多不同的framework和不同的函数.这里我们讲一下这个过程背后的东西. ...

  10. IFE春季班第一阶段任务(请仔细阅读)

    第一阶段的主要目标是帮助大家 了解.认识.学习.掌握HTML及CSS.第一阶段任务从 3月14日 开始,持续到 4月3日.当然,您也可以在这个时间以后继续自行实践练习. 第一阶段任务一共有 12 个题 ...