#include<bits/stdc++.h> #define PII pair<int, int> #define STC static #define fi first #define se second usingnamespace std; constint N = 1e5 + 5, M = 2e5 + 5; int n; structEdge { int ne, ver; } e[M]; int h[N], idx = 0; bool vis[N]; voidadd(int x, int y) { e[idx] = {h[x], y}, h[x] = idx++; } intfind3c() { int res = 0; for (int x = 1; x <= n; ++x) { for (int i = h[x]; i != -1; i = e[i].ne) vis[e[i].ver] = true; for (int i = h[x]; i != -1; i = e[i].ne) for (int j = h[e[i].ver]; j != -1; j = e[j].ne) res += vis[e[j].ver]; for (int i = h[x]; i != -1; i = e[i].ne) vis[e[i].ver] = false; } return res; } intmain() { int m; STC PII _e[M]; STC int deg[N]; scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) h[i] = -1; for (int i = 1; i <= m; ++i) { scanf("%d%d", &_e[i].fi, &_e[i].se); if (_e[i].fi < _e[i].se) swap(_e[i].fi, _e[i].se); ++deg[_e[i].fi], ++deg[_e[i].se]; } for (int i = 1; i <= m; ++i) { if (_e[i].fi == _e[i].se) continue; if (deg[_e[i].fi] >= deg[_e[i].se]) add(_e[i].fi, _e[i].se); else add(_e[i].se, _e[i].fi); } printf("%d\n", find3c()); return0; }
#include<bits/stdc++.h> #define LL long long usingnamespace std; constint N = 1e5 + 5, M = 2e5 + 5; int n; structEdge { int ne, ver; } e[M << 1]; int h[N], idx = 0; int id[N], deg[N], rk[N]; int cnt[N]; voidadd(int x, int y) { e[idx] = {h[x], y}, h[x] = idx++; } LL find4c() { LL res = 0; for (int x = 1; x <= n; ++x) { for (int i = h[x]; i != -1; i = e[i].ne) if (rk[x] > rk[e[i].ver]) for (int j = h[e[i].ver]; j != -1; j = e[j].ne) if (rk[x] > rk[e[j].ver]) res += cnt[e[j].ver]++; for (int i = h[x]; i != -1; i = e[i].ne) if (rk[x] > rk[e[i].ver]) for (int j = h[e[i].ver]; j != -1; j = e[j].ne) cnt[e[i].ver] = 0; } return res; } boolcmp(int x, int y) { return deg[x] == deg[y] ? x < y : deg[x] < deg[y]; } intmain() { int m; scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) h[i] = -1, id[i] = i; for (int i = 1, u, v; i <= m; ++i) { scanf("%d%d", &u, &v); ++deg[u], ++deg[v]; add(u, v), add(v, u); } sort(id + 1, id + 1 + n, cmp); for (int i = 1; i <= n; ++i) rk[id[i]] = i; printf("%lld\n", find4c()); return0; }