xtu summer individual 2 E - Double Profiles
Double Profiles
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 ≠ i, k ≠ 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
3 3
1 2
2 3
1 3
3
3 0
3
4 1
1 3
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的更多相关文章
- 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 ...
- CodeForces - 154C:Double Profiles (hash+排序)
You have been offered a job in a company developing a large social network. Your first task is conne ...
- xtu summer individual 6 B - Number Busters
Number Busters Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on CodeForces. ...
- xtu summer individual 4 C - Dancing Lessons
Dancing Lessons Time Limit: 5000ms Memory Limit: 262144KB This problem will be judged on CodeForces. ...
- xtu summer individual 3 C.Infinite Maze
B. Infinite Maze time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- xtu summer individual 2 C - Hometask
Hometask Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Origin ...
- 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 ...
- xtu summer individual 2 D - Colliders
Colliders Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Origi ...
- xtu summer individual 1 C - Design the city
C - Design the city Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu D ...
随机推荐
- 题解报告:poj 2631 Roads in the North(最长链)
Description Building and maintaining roads among communities in the far North is an expensive busine ...
- ubuntu 16.0.4安装MySQL5.7
系统版本 root@sishen:~# uname -a Linux sishen 4.10.0-35-generic #39~16.04.1-Ubuntu SMP Wed Sep 13 09:02: ...
- Design Patterns Uncovered: The Chain Of Responsibility Pattern
Chain of Responsibility in the Real World The idea of the Chain Of Responsibility is that it avoids ...
- AJPFX谈JAVA新手问题之异常处理使用不当
★空的 catch 语句块 犯这种错误的人比较少,一般发生在刚学会 Java 或者刚参加工作不久的人身上. 所谓“空 catch 语句块”就是在 catch 语句块中没有对异常作任何处理(比如记错误日 ...
- java写跳一跳辅助程序
##起初是想使用按键精灵脚本程序控制,但还是选择熟悉的java.我这里使用了工具,造成延迟问题.也求教:java控制安卓的正确姿势, 参考了.NET玩跳一跳,思路都是一样的,只不过使用ADB控制安卓的 ...
- 洛谷 U10223 Cx大帝远征埃及
题目背景 众所周知,Cx是一个宇宙大犇.Cx能文善武,一直在为大一统的实现而努力奋斗着.Cx将调用他的精锐军队,一个精锐士兵最多可以战胜十个埃及士兵.同时Cx是个爱才的人,他想要制定一份能使在占领埃及 ...
- 详解nginx.conf文件配置项(包括负载均衡)
http://www.cnblogs.com/hsapphire/archive/2010/04/08/1707109.html #运行用户 user nobody nobody; #启动进程 wo ...
- linux截图工具
推荐:deepin-scrot 满足功能: 能够自定义快捷键(Ctrl+Alt+A) 小巧快速自定义选择区域进行截图 有简单的绘图功能 可以快速的保存到剪切版(双击图片) P.S.:双重截图
- Python 风格规范
分号 不要在行尾加分号, 也不要用分号将两条命令放在同一行. 行长度 每行不超过80 个字符 例外: 如果使用Python 2.4 或更早的版本, 导入模块的行可能多于80 个字符. Pyth ...
- 汇编4OPCODE
opcode原理 前缀域 切换操作数大小前缀 : 066h 可以将32位的操作数切换成16位的操作数 B8 00010000 | MOV EAX,0x100 66:B8 0001 | MOV ...