思路:以关系建图,遍历每个点,没遍历就dfs搜一遍,标记一下
#include<bits/stdc++.h>
using namespace std;
const int maxn = 10000000 + 10;
int d[maxn], u[maxn], v[maxn];
inline int read() {
int x = 0, y = 0;
char c;
while (!isdigit(c))y |= c == '-', c = getchar();
while (isdigit(c))x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
return y ? -x : x;
}
int main() {
int n, i, m, ans = 0;
n = read();
m = read();
//cin>>n>>m;
memset(d, 0, sizeof(d));
for (int i = 0; i < m; i++) {
//cin>>u[i]>>v[i];
u[i] = read();
v[i] = read();
d[u[i]]++;
d[v[i]]++;
}
for (int i = 0; i < m; i++) {
if (d[u[i]] > 1 && d[v[i]] > 1) {
ans += (d[u[i]] - 1) * (d[v[i]] - 1) * 2;
}
}
cout << ans;
return 0;
}