题意:

给出一个n个节点m条边的有向图,求如图所示的菱形的个数。

这四个节点必须直接相邻,菱形之间不区分节点b、d的个数。

分析:

我们枚举每个a和c,然后求出所有满足a邻接t且t邻接c的节点的个数记为r。

那么分别以a、c为左右端点的菱形的个数就是r的二元组合。

 #include <cstdio>
#include <vector> using namespace std; const int maxn = + ;
bool G[maxn][maxn];
vector<int> nxt[maxn]; int main()
{
//freopen("in.txt", "r", stdin);
int n, m;
scanf("%d%d", &n, &m);
for(int i = ; i < m; ++i)
{
int a, b;
scanf("%d%d", &a, &b);
G[a][b] = true;
nxt[a].push_back(b);
} int ans = ;
for(int a = ; a <= n; ++a)
for(int c = ; c <= n; ++c)
{
if(a != c)
{
int r = ;
for(int b = ; b < nxt[a].size(); ++b)
{
if(nxt[a][b] != a && nxt[a][b] != c && G[nxt[a][b]][c])
r++;
}
ans += r*(r-)/;
}
} printf("%d\n", ans); return ;
}

代码君

CodeForces 489D Unbearable Controversy of Being的更多相关文章

  1. CodeForces 489D Unbearable Controversy of Being (搜索)

    Unbearable Controversy of Being 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/B Descrip ...

  2. CodeForces 489D Unbearable Controversy of Being (不知咋分类 思维题吧)

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

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

    http://codeforces.com/problemset/problem/489/D D. Unbearable Controversy of Being time limit per tes ...

  4. 【Codeforces 489D】Unbearable Controversy of Being

    [链接] 我是链接,点我呀:) [题意] 让你找到(a,b,c,d)的个数 这4个点之间有4条边有向边 (a,b)(b,c) (a,d)(d,c) 即有两条从a到b的路径,且这两条路径分别经过b和d到 ...

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

    这道题我临场想到了枚举菱形的起点和终点,然后每次枚举起点指向的点,每个指向的点再枚举它指向的点看有没有能到终点的,有一条就把起点到终点的路径个数加1,最后ans+=C(路径总数,2).每两个点都这么弄 ...

  6. 【cf489】D. Unbearable Controversy of Being(暴力)

    http://codeforces.com/contest/489/problem/D 很显然,我们只需要找对于每个点能到达的深度为3的点的路径的数量,那么对于一个深度为3的点,如果有a种方式到达,那 ...

  7. [CF489D]Unbearable Controversy of Being

    题目大意:求有向图中这种图的数量 从分层图来考虑,这是一个层数为3的图 枚举第一个点能到达的所有点,对他们进行BFS求第三层的点(假装它是BFS其实直接枚举效果一样) 代码: #include< ...

  8. Codeforces Round #277.5 (Div. 2) ABCDF

    http://codeforces.com/contest/489 Problems     # Name     A SwapSort standard input/output 1 s, 256 ...

  9. Codeforces Round #277.5 (Div. 2)

    题目链接:http://codeforces.com/contest/489 A:SwapSort In this problem your goal is to sort an array cons ...

随机推荐

  1. IIS Express start introduction and applicationHost modification

    1. First you need create a web project in VS 2. When you finish your project, click start then IIS E ...

  2. silverlight 控件自定义样式 实现方法

    1:在app.xaml中加入需实现的样式,如: <Application.Resources> <Style x:Key="NodeStyle" TargetTy ...

  3. Directx3D SimpleSample Sample

    在d3d 2010 june这个版本里的samples 不知道为什么SimpleSample Sample 这个 它的documents基本等于没有 Starting point for new Di ...

  4. 以“图片渐入渐出”为例讲述jQuery插件的具体实现

    首先声明,此代码以网友“斯迈欧”原创作为此例的讲解: 在这之前我们先看看我们要做的效果是什么样的: 解析下面的样式:我们要图片在过“一定时间”后自动切换,在右下角处有小方块似数字1,2,3,4,这些数 ...

  5. PHP之SQL防注入代码集合(建站常用)

    SQL防注入代码一 <?php if (!function_exists (quote)) { function quote($var) { if (strlen($var)) { $var=! ...

  6. apache 多域名配置

    一直不明白apache多域名配置的问题,所以只能用不同的端口来配置,现在终于搞懂了一点 首先,开启apache的vhost模块 找到配置文件httpd.conf中的下面两行 #LoadModule v ...

  7. hdu 1166 树状数组 线段树入门

    点修改 区间求和 #include <cstdio> #include <cstdlib> #include <cmath> #include <map> ...

  8. C/C++框架和库

    http://blog.csdn.net/xiaoxiaoyeyaya/article/details/42541419 值得学习的C语言开源项目 - 1. Webbench Webbench是一个在 ...

  9. 利用hadoop自带程序运行wordcount

    1.启动hadoop守护进程 bin/start-all.sh 2.在hadoop的bin目录下建立一个input文件夹 JIAS-MacBook-Pro:hadoop- jia$ mkdir inp ...

  10. HBase入门

    /×××××××××××××××××××××××××××××××××××××××××/ Author:xxx0624 HomePage:http://www.cnblogs.com/xxx0624/ ...