[CF489D]Unbearable Controversy of Being
题目大意:求有向图中这种图的数量

从分层图来考虑,这是一个层数为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的更多相关文章
- CodeForces 489D Unbearable Controversy of Being (搜索)
Unbearable Controversy of Being 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/B Descrip ...
- CodeForces 489D Unbearable Controversy of Being (不知咋分类 思维题吧)
D. Unbearable Controversy of Being time limit per test 1 second memory limit per test 256 megabytes ...
- 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 ...
- CodeForces 489D Unbearable Controversy of Being
题意: 给出一个n个节点m条边的有向图,求如图所示的菱形的个数. 这四个节点必须直接相邻,菱形之间不区分节点b.d的个数. 分析: 我们枚举每个a和c,然后求出所有满足a邻接t且t邻接c的节点的个数记 ...
- 【cf489】D. Unbearable Controversy of Being(暴力)
http://codeforces.com/contest/489/problem/D 很显然,我们只需要找对于每个点能到达的深度为3的点的路径的数量,那么对于一个深度为3的点,如果有a种方式到达,那 ...
- Codeforces Round #277.5 (Div. 2)D Unbearable Controversy of Being (暴力)
这道题我临场想到了枚举菱形的起点和终点,然后每次枚举起点指向的点,每个指向的点再枚举它指向的点看有没有能到终点的,有一条就把起点到终点的路径个数加1,最后ans+=C(路径总数,2).每两个点都这么弄 ...
- 【Codeforces 489D】Unbearable Controversy of Being
[链接] 我是链接,点我呀:) [题意] 让你找到(a,b,c,d)的个数 这4个点之间有4条边有向边 (a,b)(b,c) (a,d)(d,c) 即有两条从a到b的路径,且这两条路径分别经过b和d到 ...
- Codeforces Round #277.5 (Div. 2) ABCDF
http://codeforces.com/contest/489 Problems # Name A SwapSort standard input/output 1 s, 256 ...
- Codeforces Round #277.5 (Div. 2)
题目链接:http://codeforces.com/contest/489 A:SwapSort In this problem your goal is to sort an array cons ...
随机推荐
- 面试题思考:java中快速失败(fail-fast)和安全失败(fail-safe)的区别是什么?
一:快速失败(fail—fast) 在用迭代器遍历一个集合对象时,如果遍历过程中对集合对象的内容进行了修改(增加.删除.修改),则会抛出Concurrent Modification Exceptio ...
- 【BZOJ4676】Xor-Mul棋盘 拆位+状压DP
[BZOJ4676]Xor-Mul棋盘 Description 一个n*m的棋盘,左上角为(1,1),右下角为(n,m).相邻的2点之间有连边(如下图中实线)特殊地,(1,i)与(n,i)也连有一条边 ...
- CodeForces 156B Suspects(枚举)
B. Suspects time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- Web 资源介绍
软件体系结构 C/S, client/server 特点: 该结构的软件, 客户端和服务端都需要编写 开发成本较高,维护较为麻烦 好处: 客户端在本地可以分担一部分运算 B/S, browser/se ...
- MyBatis动态代理查询出错
org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: org.apache. ...
- django_视图层/2.0路由层/虚拟环境
- python多线程的两种写法
1.一般多线程 import threading def func(arg): # 获取当前执行该函数的线程的对象 t = threading.current_thread() # 根据当前线程对象获 ...
- 代码艺术 CountDownTimer
/** * Schedule a countdown until a time in the future, with regular notifications on intervals along ...
- windows7下RabbitMQ的安装
一.下载资源 Rabbit MQ 是建立在强大的Erlang OTP平台上,因此安装Rabbit MQ的前提是安装Erlang.(在官网自行选择版本) 1.otp_win64_20.2.exe 下载地 ...
- django 中的视图(Views)
Views Django中views里面的代码就是一个一个函数逻辑, 处理客户端(浏览器)发送的HTTPRequest, 然后返回HTTPResponse, http请求中产生两个核心对象: http ...