题意:

给出一个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. [resource]23个python的机器学习包

    23个python的机器学习包,从常见的scikit-learn, pylearn2,经典的matlab替代orange, 到最新最酷的Theano(深度学习)和torch 7 (well,其实lua ...

  2. AngularJs遇到的小坑与技巧

    1. templateURL和路由之类的要在web server下运行. 2. 使用模板replace设为true,模板里也要有相应的标签,否则不出现任何数据. 3. 1.2版本之后,ngRoute模 ...

  3. DispatcherServlet--Spring的前置控制器作用简介

    参考网址:http://jinnianshilongnian.iteye.com/blog/1602617 Struts有一个ActionServlet,用来完成前置控制器(分发器)的功能.其实,所有 ...

  4. c库函数之scanf

    scanf()函数的原理 想象输入设备(键盘)连接着一个叫“缓冲”的东西,把缓冲认为是一个字符数组. 当你的程序执行到scanf时,会从你的缓冲区读东西,如果缓冲区是空的,就阻塞住,等待你从键盘输入. ...

  5. 有关javascript中的JSON.parse和JSON.stringify的使用一二

    有没有想过,当我们的大后台只是扮演一个数据库的角色,json在前后台的数据交换中扮演极其重要的角色时,作为依托node的前端开发,其实相当多的时间都是在处理数据,准确地说就是在处理逻辑和数据(这周实习 ...

  6. vs-ps combination error

    http://social.msdn.microsoft.com/Forums/en-US/5dfef3d9-edc1-4006-9e81-9d5326419df8/d3d10effect-compi ...

  7. 关于iOS中的文本操作-管理text fields 和 text views

    Managing Text Fields and Text Views 管理UITextField和UITextView实例 UITextField和UITextView的实例拥有两个最主要的功能:展 ...

  8. PAT-乙级-1048. 数字加密(20)

    1048. 数字加密(20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 本题要求实现一种数字加密方法.首先固 ...

  9. A Step-by-Step Guide to Your First AngularJS App

    What is AngularJS? AngularJS is a JavaScript MVC framework developed by Google that lets you build w ...

  10. C++ Variables and Basic Types Notes

    1. Type conversion: If we assign an out-of-range value to an object of unsigned type, the result is ...