题意:求该死的菱形数目。直接枚举两端的点。平均意义每一个点连接20条边,用邻接表暴力计算中间节点数目,那么中间节点任选两个与两端可组成的菱形数目有r*(r-1)/2.

代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<map>
#include<cstring>
#include<algorithm>
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rev(i,a,b) for(int i=(a);i>=(b);i--)
#define clr(a,x) memset(a,x,sizeof a)
typedef long long LL;
using namespace std; const int mod=1e9 +7;
const int maxn=3005;
const int maxm=30005; int first[maxn],nex[maxm],v[maxm],ecnt,g[maxn][maxn]; void add_(int a,int b)
{
v[ecnt]=b;
nex[ecnt]=first[a];
first[a]=ecnt++;
}
int main()
{
int n,m,x,y;
while(~scanf("%d%d",&n,&m))
{
memset(first,-1,sizeof first);ecnt=0;
memset(g,0,sizeof g);
for(int i=0;i<m;i++)
scanf("%d%d",&x,&y),add_(x,y),g[x][y]=1;
int ans=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
if(i!=j){
int r=0;
for(int e=first[i];~e;e=nex[e])
if(g[v[e]][j])r++;
ans+=r*(r-1)/2;
}
}
printf("%d\n",ans);
}
return 0;
}

D. Unbearable Controversy of Being
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Tomash keeps wandering off and getting lost while he is walking along the streets of Berland. It's no surprise! In his home town, for any pair of intersections there is exactly one way to walk from one intersection to the other one. The capital of Berland is
very different!

Tomash has noticed that even simple cases of ambiguity confuse him. So, when he sees a group of four distinct intersections abc and d,
such that there are two paths from a to c — one
through b and the other one through d, he calls
the group a "damn rhombus". Note that pairs (a, b), (b, c), (a, d), (d, c) should
be directly connected by the roads. Schematically, a damn rhombus is shown on the figure below:

Other roads between any of the intersections don't make the rhombus any more appealing to Tomash, so the four intersections remain a "damn rhombus" for him.

Given that the capital of Berland has n intersections and m roads
and all roads are unidirectional and are known in advance, find the number of "damn rhombi" in the city.

When rhombi are compared, the order of intersections b and d doesn't
matter.

Input

The first line of the input contains a pair of integers nm (1 ≤ n ≤ 3000, 0 ≤ m ≤ 30000)
— the number of intersections and roads, respectively. Next m lines list the roads, one per line. Each of the roads is given by a pair of integers ai, bi (1 ≤ ai, bi ≤ n;ai ≠ bi)
— the number of the intersection it goes out from and the number of the intersection it leads to. Between a pair of intersections there is at most one road in each of the two directions.

It is not guaranteed that you can get from any intersection to any other one.

Output

Print the required number of "damn rhombi".

Sample test(s)
input
5 4
1 2
2 3
1 4
4 3
output
1
input
4 12
1 2
1 3
1 4
2 1
2 3
2 4
3 1
3 2
3 4
4 1
4 2
4 3
output
12

Codeforces Round #277.5 (Div. 2)-D的更多相关文章

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

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

  2. Codeforces Round #277.5 (Div. 2)

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

  3. Codeforces Round #277.5 (Div. 2) --E. Hiking (01分数规划)

    http://codeforces.com/contest/489/problem/E E. Hiking time limit per test 1 second memory limit per ...

  4. 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 ...

  5. Codeforces Round #277.5 (Div. 2)-C. Given Length and Sum of Digits...

    http://codeforces.com/problemset/problem/489/C C. Given Length and Sum of Digits... time limit per t ...

  6. Codeforces Round #277.5 (Div. 2)-B. BerSU Ball

    http://codeforces.com/problemset/problem/489/B B. BerSU Ball time limit per test 1 second memory lim ...

  7. Codeforces Round #277.5 (Div. 2)-A. SwapSort

    http://codeforces.com/problemset/problem/489/A A. SwapSort time limit per test 1 second memory limit ...

  8. Codeforces Round #277.5 (Div. 2) A,B,C,D,E,F题解

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud A. SwapSort time limit per test    1 seco ...

  9. Codeforces Round #277.5 (Div. 2)B——BerSU Ball

    B. BerSU Ball time limit per test 1 second memory limit per test 256 megabytes input standard input ...

随机推荐

  1. python计算md5值

    from hashlib import md5 m = md5(') print m.hexdigest()

  2. Mac OS X 快捷键(完整篇)

    不少朋友提出要求,希望有个「高质量」的列表.其实这样的资源真是太多,平果官网就有 快捷键文档(多国语言版本).于是花了20分钟,浏览了一些网站,整理了点资源放过来供大家参考. 快捷键是通过按下键盘上的 ...

  3. 当Evernote结合MindManager

    最近潜心研究Evernote(印象笔记)在数据存储和GTD规划方面的运用,感觉到的震撼和惊艳,一如当初开始接触MindManager的时候! 我非常喜欢这个SaaS的软件,以至于我将我国际版的Ever ...

  4. Android UI ActionBar功能-启动ActionBar

    官方帮助文档:http://wear.techbrood.com/training/basics/actionbar/index.html ------------------------------ ...

  5. #include <stdbool.h>

    可以使用bool和true.false 输出是1或者0 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdb ...

  6. Acdream1084 寒假安排 求n!中v因子个数

    题目链接:pid=1084">点击打开链接 寒假安排 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 128000/64000 ...

  7. linux 命令之 uptime

    uptime 命令是用来查询linux系统负载的. 命令格式 uptime [OPTION] -V 显示版本号 不带參数的 uptime 直接输出系统负载. 何为系统负载呢? 系统平均负载被定义为在特 ...

  8. 学习Java这几个快捷键你得知道(不断更新中)

    java中的System.out.println();的快捷键    --------先输入sysout  在按 alt + /

  9. linux下的进程、网络、性能监控命令

    进程监控 端口   1)netstat -anp | grep xxx   2)lsof  -i:<port> 句柄    lsof  -n | grep xxxx 线程栈   1)gst ...

  10. SqlServer2008 数据库可疑

    今天遇到数据库可疑,以前都是直接删了还原,这次没有最新的备份文件,一起看看脚本怎么解决 --最好一句句执行,方便看到错误 USE MASTER GO --开启数据库选项"允许更新" ...