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 ...
随机推荐
- 人品问题 树形dp
题目 网上出现了一种高科技产品——人品测试器.只要你把你的真实姓名输入进去,系统将自动输出你的人品指数.把儿不相信自己的人品为0.经过了许多研究后,把儿得出了一个更为科学的人品计算方法.这种方法的理论 ...
- H5页面快速搭建之高级字体应用实践
原文出处: 淘宝前端团队(FED)- 龙驭 背景 最近在开发一个 H5 活动页快速搭建平台,可以通过拖拽编辑图片,文字等元素组件,快速搭建出一个移动端的活动页面,基本交互和成品效果类似 PPT 软件. ...
- archsummit_bj2016
http://bj2016.archsummit.com/schedule 大会日程 2016年12月02日,星期五 7:45-9:00 签到 8:45-9:00 开始入场 9:00-9:30 开场致 ...
- DOM编程练习(慕课网题目)
编程练习 制作一个表格,显示班级的学生信息. 要求: 1. 鼠标移到不同行上时背景色改为色值为 #f2f2f2,移开鼠标时则恢复为原背景色 #fff 2. 点击添加按钮,能动态在最后添加一行 3. 点 ...
- AngularJS 表单验证手机号(非必填)
代码: <form ng-app="myApp" ng-controller="validateCtrl" name="myForm" ...
- mac下iterm2配置安装,通过expact实现保存账号,及通过跳板登陆配置
在参考了几款mac不错的ssh工具外,最终选择使用iterm2.本来打算用FinalShell,安装后发现其icon在访达中根本不现实,而且每次访问还需要输入管理员账号密码,强迫症根本受不了... 官 ...
- Oracle AWR报告的生成
生成AWR报告需要dbms_workload_repository包的权限. 一.以oracle用户登录到数据库服务器 二.进入SQLPLUS 三.执行脚本 @?/rdbms/admin/awrrpt ...
- 深入解析Web Services
SOA,面向服务器建构,是一款架构,这几年虽然没前几年那么流行,但是还是有很多企业在用,而Web Services是目前适合做SOA的主要技术之一,通过使用Web Services,应用程序可以对外发 ...
- 洛谷 P2053 [SCOI2007]修车
题目描述 同一时刻有N位车主带着他们的爱车来到了汽车维修中心.维修中心共有M位技术人员,不同的技术人员对不同的车进行维修所用的时间是不同的.现在需要安排这M位技术人员所维修的车及顺序,使得顾客平均等待 ...
- SQLite – 删除表
SQLite -删除表 SQLite DROP TABLE语句用于删除一个表定义和所有相关的数据,索引.触发器.约束和规范许可表. 你使用这个命令时必须小心,因为一旦一个表被删除然后表中所有可用的信息 ...