题目大意:求有向图中这种图的数量

从分层图来考虑,这是一个层数为3的图

枚举第一个点能到达的所有点,对他们进行BFS求第三层的点(假装它是BFS其实直接枚举效果一样)

代码:

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#define ll long long
#define M 100010
using namespace std;
struct point{
int to,next;
}e[M<<];
int n,m,num;
int head[M],vis[M];
ll ans;
void add(int from,int to)
{
e[++num].next=head[from];
e[num].to=to;
head[from]=num;
}
void bfs(int x)
{
memset(vis,,sizeof(vis));
queue<int>q;
for(int i=head[x];i;i=e[i].next) q.push(e[i].to);
while(!q.empty())
{
int p=q.front(); q.pop();
for(int i=head[p];i;i=e[i].next)
{
int to=e[i].to;
if(to!=x) vis[to]++;
}
}
for(int i=;i<=n;i++) ans+=(ll)(vis[i]-)*vis[i]/;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++)
{
int x,y; scanf("%d%d",&x,&y);
add(x,y);
}
for(int i=;i<=n;i++) bfs(i);
printf("%lld",ans);
return ;
}

[CF489D]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

    题意: 给出一个n个节点m条边的有向图,求如图所示的菱形的个数. 这四个节点必须直接相邻,菱形之间不区分节点b.d的个数. 分析: 我们枚举每个a和c,然后求出所有满足a邻接t且t邻接c的节点的个数记 ...

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

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

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

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

  7. 【Codeforces 489D】Unbearable Controversy of Being

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

  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. Appcompat实现Action Bar的兼容性处理

    Appcompat实现Action Bar时,如果使用到split action bar或者Navigating Up with the App Icon需要考虑兼容性.下面介绍下split acti ...

  2. 160726、jQuery常用操作

    一.简介   定义  jQuery创始人是美国John Resig,是优秀的Javascript框架: jQuery是一个轻量级.快速简洁的javaScript库. jQuery对象  jQuery产 ...

  3. css3的3d属性集合

    css3的3d属性集合 想进入css3的3d世界必须知道一下几个属性及其用法. 当然在进入属性介绍之前我想你必须知道3维坐标,附上一张经典图如下: 我想不用解释了吧.之后要平移和旋转都是在这个基础之上 ...

  4. Oracle数据库命令行下数据的导入导出

    //设置导入导出字符集,导入导出都要设置一下 export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK //导出 exp system/oracle@orcl file=/u ...

  5. Java 面向对象编程介绍

    面向对象的概念 类与对象的关系 封装 面向对象 面向过程: 强调的是过程(动作) 面向对象: 强调的是对象(实体) 面向对象的特点 面向对象就是一种常见的思想,符合人们的思考习惯; 面向对象的出现,将 ...

  6. JVM的JIT机制

    因为 JVM 的 JIT 机制的存在,如果某个函数被调用多次之后,JVM 会尝试将其编译成为机器码从而提高执行速度.

  7. If 条件控制 & while循环语句

    Python条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块. 可以通过下图来简单了解条件语句的执行过程: if 语句 Python中if语句的一般形式如下所示: i ...

  8. 目标检测之R-FCN

    R-FCN:Object Detection via Region-based Fully Convolutional Networks R-FCN的网络结构 一个Base的convolutional ...

  9. 利用VMware克隆linux虚拟机需要注意的事项

    利用VMware克隆虚拟机需要注意的问题 2018年03月30日 18:20:29 温文尔雅的流氓 阅读数:1343更多 个人分类: linux   版权声明:本文为博主原创文章,未经博主允许不得转载 ...

  10. 神经网络中的数据预处理方法 Data Preprocessing

    0.Principal component analysis (PCA) Principal component analysis (PCA) is a statistical procedure t ...