Pagini recente » Cod sursa (job #2367926) | Cod sursa (job #924933) | Cod sursa (job #1742244)
#include <bits/stdc++.h>
#define bits(x) __builtin_popcount(x)
using namespace std;
const int MMAX = 66000, //:O
NMAX = 4100,
B = 16;
struct PII {
int x, y;
inline PII() { }
inline PII(int _x, int _y) {
x = _x;
y = _y;
}
};
class hpstream {
private:
static const int BMAX = 1<<17;
FILE *file;
int buff;
char str[BMAX];
inline char nextch(void) {
if(buff==BMAX) {
fread(str, 1, BMAX, file);
buff = 0;
}
return str[buff++];
}
public:
hpstream() {}
hpstream(const char *str) {
file = fopen(str, "r");
buff = BMAX;
}
inline hpstream &operator>> (int &arg) {
char ch;
arg = 0;
while(!isdigit(ch=nextch()));
arg=ch-'0';
while(isdigit((ch=nextch())))
arg=arg*10+ch-'0';
return *this;
}
void close(void) {
fclose(file);
}
};
int g[NMAX][NMAX/B],
x[NMAX],
y[NMAX];
int main(void) {
hpstream fs("triplete.in");
ofstream gs("triplete.out");
int n, m, ant;
ant = 0; ///(Antwort)
fs>>n>>m;
for(int i=1; i<=m; ++i) {
fs>>x[i]>>y[i];
if(x[i] < y[i])
swap(x[i], y[i]);
g[x[i]][y[i]/B] |= 1 << (y[i] % B);
}
for(int i=1; i<=m; ++i)
for(int j=0; j<=n/B; ++j)
ant+=bits(g[x[i]][j]&g[y[i]][j]);
gs<<ant<<'\n';
fs.close();
gs.close();
return 0;
}