數一數 a-> ? -> b的個數
include<cstdio> #include<cstdlib> #include<cstring> #include<vector> #include<map> using namespace std; typedef long long int int64; vector<int> to[3010]; int main() { int n, k; scanf("%d %d", &n, &k); for(int lx = 0;lx < k;lx++){ int a, b; scanf("%d %d", &a, &b); to[a-1].push_back(b-1); } int64 count = 0; int64 cnt[3010]; for(int lx = 0;lx < n;lx++){ //printf("prc on %d\n", lx); int qs = 0, qe = 1; memset(cnt, 0, sizeof(cnt)); for(int xx = 0;xx < to[lx].size();xx++){ int prc = to[lx][xx]; for(int yy = 0; yy < to[prc].size(); yy++) cnt[to[prc][yy]]++; } for(int xx = 0;xx < n;xx++){ if(xx == lx) continue; //printf("count to %d -> %I64d\n", xx, cnt[xx]); count += cnt[xx]*(cnt[xx]-1)/2; } } printf("%I64d\n", count); // for(;;); return 0; }
沒有留言:
張貼留言