统计无向图中三角形的个数,复杂度m*sqrt(m).
#include#include #include #include #include using namespace std; #define LL long long vector G[100005]; set st; int vis[100005], link[100005], out[100005]; int main(void) { LL ans, sum; int n, i, j, m, k, x, y, z, B; while(scanf("%d%d", &n, &m)!=EOF) { B = sqrt(m); st.clear(); for(i=1;i<=n;i++) { G[i].clear(); vis[i] = out[i] = link[i] = 0; } for(i=1;i<=m;i++) { scanf("%d%d", &x, &y); G[x].push_back(y), out[x]++; G[y].push_back(x), out[y]++; st.insert((LL)x*n+y); st.insert((LL)y*n+x); } ans = 0; for(i=1;i<=n;i++) { x = i; vis[x] = 1; for(j=0;j