Pagini recente » Cod sursa (job #2178959) | Concursuri organizate de infoarena | Cod sursa (job #821760) | Cod sursa (job #1512934) | Cod sursa (job #1587090)
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
#define Nmax 4096
#define Mmax 65537
#define Bmax 64
ifstream fin ( "triplete.in" );
ofstream fout ( "triplete.out" );
typedef unsigned long long ULL;
ULL v[Nmax][Bmax];
pair < int, int > E[Mmax];
void Addbit ( int x, int y ){
int Bucket = Bmax - (y / 64) - 1;
int Bit = y % 64;
v[x][Bucket] |= ( 1LL << Bit );
return;
}
long long Sol = 0;
void Combine ( int x, int y ){
long long rez = 0;
for ( int i = 0; i < Bmax; ++i )
Sol += __builtin_popcountll (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();
for ( int i = 1; i <= M; ++i ){
x = ReadInt() - 1;
y = ReadInt() - 1;
E[i] = make_pair(x,y);
Addbit ( x, y );
Addbit ( y, x );
}
for ( int i = 1; i <= M; ++i )
Combine ( E[i].first, E[i].second );
fout << Sol / 3;
return 0;
}