Test instructions
N (3000) points m (30000) edges of a simple graph statistics the number of diamonds drawn in the question
Ideas:
We can think of the diamond as two paths with a distance of 2 a->c and then assuming that we enumerate the number of path strips with a i->j distance of 2, we can calculate it with a simple combination number.
If the violent calculation of the number of paths is n^3, but we can use the distance of 2, we use the adjacency table and the adjacency matrix to enumerate all sides of the edge m at the same time by the adjacency table and then know that the i->k distance is 1 then we enumerate all n point adjacency matrix to determine if K->j has a road I-&G T;j path complexity of length 2 is O (nm)
Code:
#include <cstdio> #include <iostream> #include <cstring> #include <string> #include < algorithm> #include <map> #include <set> #include <vector> #include <queue> #include < cstdlib> #include <ctime> #include <cmath> #include <bitset>using namespace std; #define N 3010typedef long ll;int N, m; LL ans;vector<int> ed[n];int Maz[n][n], F[n][n];int main () {scanf ("%d%d", &n, &m); for (int i = 1; I <= m; i++) {int u, v; scanf ("%d%d", &u, &v); MAZ[U][V] = 1; Ed[u].push_back (v); } for (int i = 1; I <= N, i++) {for (int j = 0; J < ed[i].size (); + j) {for (int k = 1; k < ; = N; k++) {if (maz[ed[i][j]][k]) f[i][k]++; }}} for (int i = 1, i <= N; i++) {for (int j = 1; J <= N; j + +) {if (i! = J && Amp F[I][J] > 1) ans + = (LL) (F[i][j]-1) * F[i][j]/2; printf ("%d%d%d\n", I, J, F[i][j]); }} printf ("%i64d\n", ans); return 0;}
Codeforces 489D unbearable Controversy of Being