xtu summer individual 2 E - Double Profiles

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 31 22 31 3

Output

3

Input

3 0

Output

3

Input

4 11 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

Codeforces Round #109 (Div. 1)

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cmath>
 5 #include <algorithm>
 6 #include <climits>
 7 #include <vector>
 8 #include <queue>
 9 #include <cstdlib>
10 #include <string>
11 #include <set>
12 #define LL long long
13 #define INF 0x3f3f3f3f
14 using namespace std;
15 const int maxn = 1000100;
16 LL _hash[maxn],A[maxn],B[maxn];
17 int main(){
18     int n,m,x,y,i;
19     LL ans = 0,cnt1 = 0,cnt2 = 0,pre1 = -1,pre2 = -1;
20     _hash[1] = 1;
21     scanf("%d %d",&n,&m);
22     for(i = 2; i <= n; i++)
23         _hash[i] = _hash[i-1]*3;
24     for(i = 0; i < m; i++){
25         scanf("%d%d",&x,&y);
26         A[x] += _hash[y];
27         A[y] += _hash[x];
28     }
29     for(i = 1; i <= n; i++)
30         B[i] += A[i]+_hash[i];
31     sort(A+1,A+n+1);
32     sort(B+1,B+n+1);
33     for(i = 1; i <= n; i++){
34         if(A[i] == pre1){
35             cnt1++;
36             ans += cnt1;
37         }else{
38             cnt1 = 0;
39             pre1 = A[i];
40         }
41         if(B[i] == pre2){
42             cnt2++;
43             ans += cnt2;
44         }else{
45             cnt2 = 0;
46             pre2 = B[i];
47         }
48     }
49     printf("%I64d\n",ans);
50     return 0;
51 }

xtu summer individual 2 E - Double Profiles

时间: 2024-11-22 16:18:39

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

xtu summer individual 6 B - Number Busters

Number Busters Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Original ID: 382B64-bit integer IO format: %I64d      Java class name: (Any) Arthur and Alexander are number busters. Today they've got a competition.

xtu summer individual 1 E - Palindromic Numbers

E - Palindromic Numbers Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Description A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the same when its digits are reversed. In this

xtu summer individual 6 D - Checkposts

Checkposts Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Original ID: 427C64-bit integer IO format: %I64d      Java class name: (Any) Your city has n junctions. There are m one-way roads between the junctions. A

xtu summer individual 5 D - Subsequence

Subsequence Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 353064-bit integer IO format: %I64d      Java class name: Main There is a sequence of integers. Your task is to find the longest subsequence that sa

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 HDU. Original ID: 329564-bit integer IO format: %I64d      Java class name: Main XQ,one of the three Sailormoon girls,is usually playing mobile games o

xtu summer individual 2 C - Hometask

Hometask Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Original ID: 154A64-bit integer IO format: %I64d      Java class name: (Any) Sergey attends lessons of the N-ish language. Each lesson he receives a hometas

xtu summer individual 5 F - Post Office

Post Office Time Limit: 1000ms Memory Limit: 10000KB This problem will be judged on PKU. Original ID: 116064-bit integer IO format: %lld      Java class name: Main There is a straight highway with villages alongside the highway. The highway is repres

xtu summer individual 5 A - To Add or Not to Add

To Add or Not to Add Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Original ID: 231C64-bit integer IO format: %I64d      Java class name: (Any) A piece of paper contains an array of n integers a1, a2, ..., an. Y

xtu summer individual 5 E - Burning Bridges

Burning Bridges Time Limit: 5000ms Memory Limit: 32768KB This problem will be judged on ZJU. Original ID: 258864-bit integer IO format: %lld      Java class name: Main Ferry Kingdom is a nice little country located on N islands that are connected by