Pagini recente » Cod sursa (job #2908818) | Cod sursa (job #321997) | Cod sursa (job #2056404) | Cod sursa (job #2439104) | Cod sursa (job #1587157)
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
#define Nmax 4136
#define Mmax 65537
#define Bmax 31
ifstream fin ( "triplete.in" );
ofstream fout ( "triplete.out" );
unsigned int v[Nmax][Nmax/Bmax];
pair < int, int > E[Mmax];
int Buckets;
long long Sol = 0;
void Combine ( int x, int y ){
long long rez = 0;
for ( int i = 0; i < Bmax; ++i )
Sol += __builtin_popcount (v[x][i] & v[y][i]);
}
string Buffer;
string :: iterator it;
int ReadInt(){
int nr = 0;
while ( *it < '0' || *it > '9' )
it++;
while ( *it >= '0' && *it <= '9' ){
nr = nr * 10 + ( *it - '0' );
it++;
}
return nr;
}
int main(){
int N, M, x, y;
getline( fin, Buffer, (char)0 );
it = Buffer.begin();
N = ReadInt();
M = ReadInt();
Buckets = (N-1)/Bmax;
for ( int i = 1; i <= M; ++i ){
E[i].first = (ReadInt() - 1);
E[i].second = (ReadInt() - 1);
v[E[i].first][(E[i].second / 31)] |= ( 1LL << (E[i].second % 31) );
v[E[i].second][(E[i].first / 31)] |= ( 1LL << (E[i].first % 31) );
}
for ( int i = 1; i <= M; ++i )
Combine ( E[i].first, E[i].second );
fout << Sol / 3;
return 0;
}