Xtu summer individual 2 E-double profiles

Source: Internet
Author: User
Double profilestime limit: 3000 msmemory limit: 262144 kbthis 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 containsNRegistered profiles, numbered from 1N. Some pairs there are friends (the "friendship" relationship is mutual, that is, ifIIs friendsJ, ThenJIs also friendsI). Let's say that profilesIAndJ(I  =J) Are doubles, if for any profileK(K  =I,K  =J) One of the two statements is true: eitherKIs friendsIAndJ, OrKIsn' t friends with either of them. Also,IAndJCan be friends or not be friends.

Your task is to count the number of different unordered pairs (I, Bytes,J), Such that the profilesIAndJAre doubles. Note that the pairs are unordered, that is, pairs (A, Bytes,B) And (B, Bytes,A) Are considered identical.

Input

The first line contains two space-separated IntegersNAndM(1 digit ≤ DigitNLimit ≤ limit 106, 0 limit ≤ limitMLimit ≤ limit 106),-the number of profiles and the number of pairs of friends, correspondingly.

NextMLines contains descriptions of pairs of friends in the format"V U", WhereVAndU(1 digit ≤ DigitV, Bytes,ULimit ≤ limitN, Bytes,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 memory ++. 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, Program 3) AND (2, program 4 ).

Sourcecodeforces 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 long13 #define INF 0x3f3f3f3f14 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 }
View code

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.