Codeforces 469D Unbearable Controversy of Being

原创 2015年11月17日 18:59:53

题目链接:http://codeforces.com/problemset/problem/489/D


题意:给出一个有向图,求有多少个如下的棱形(2个点之间可以有多个棱形)


思路:枚举2个点A,B然后找出所有与A相连的点是否与B相,相连则s++,这2个点之间的棱形就是s*(s-1)/2


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#define maxn 3030
using namespace std;

int G[maxn][maxn];
vector <int> link[maxn];


int main()
{
    int n,m;
    while (scanf("%d%d",&n,&m)!=EOF)
    {
        memset(G,0,sizeof(G));
        memset(link,0,sizeof(link));
        for (int i=0;i<m;i++)
        {
            int u,v;
            scanf("%d%d",&u,&v);
            G[u][v]=1;
            link[u].push_back(v);
        }

        int res=0;
        for (int i=1;i<=n;i++)
        {
            for (int j=1;j<=n;j++)
            {
                if (i==j) continue;
                int sum=0;
                for (int k=0;k<link[i].size();k++)
                {
                    int v=link[i][k];
                    if (G[v][j]==1) sum++;
                }
                res+=sum*(sum-1)/2;
            }
        }
        printf("%d\n",res);
    }
}



相关文章推荐

Codeforces Round #277.5(Div. 2) D. Unbearable Controversy of Being【暴力】

D. Unbearable Controversy of Being time limit per test 1 second memory limit per test 256 me...

【Codeforces】 489D Unbearable Controversy of Being

暴力求解即可。。。 #include #include #include #include #include #include #include #include #i...

Codeforces Round #277.5 (Div. 2) D——Unbearable Controversy of Being

D. Unbearable Controversy of Being time limit per test 1 second memory limit per test 256 me...

Codeforces 498D Unbearable Controversy of Being(暴力求菱形个数)

n(≤3000)个点m(≤30000)条边的有向图,统计下图这种菱形的数量。
  • Just_Lm
  • Just_Lm
  • 2017年01月28日 16:00
  • 108

cf489D. Unbearable Controversy of Being

D. Unbearable Controversy of Being time limit per test 1 second memory limit per test 25...

Codeforces Round #277.5 (Div. 2) D - Unbearable Controversy of

D. Unbearable Controversy of Being time limit per test 1 second memory limit per test 25...

Codeforces 469D Two Sets【思维+并查集】

D. Two Sets time limit per test 1 second memory limit per test 256 megabytes input stand...

Codeforces 469C 24 Game【思维+模拟】

C. 24 Game time limit per test 1 second memory limit per test 256 megabytes input standa...

CodeForces 469B Chat Online

CodeForces 469B   Chat Online Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I6...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Codeforces 469D Unbearable Controversy of Being
举报原因:
原因补充:

(最多只允许输入30个字)