【链接】 我是链接,点我呀:)

【题意】

让你找到(a,b,c,d)的个数
这4个点之间有4条边有向边
(a,b)(b,c)
(a,d)(d,c)
即有两条从a到b的路径,且这两条路径分别经过b和d到达c

【题解】

我们枚举a,c
然后找到这样的b的个数cntb,其中a到b有一条边,b到c也有一条边
显然从这cntb个b中取2个
就能组成b和d了。
即C(N,2)
怎么得到这样的b的个数呢
先枚举a的所有出点v,然后看看v是否和c联通即可.
联通的话,cntb++

【代码】

import java.io.*;
import java.util.*; public class Main { static InputReader in;
static PrintWriter out; public static void main(String[] args) throws IOException{
//InputStream ins = new FileInputStream("E:\\rush.txt");
InputStream ins = System.in;
in = new InputReader(ins);
out = new PrintWriter(System.out);
//code start from here
new Task().solve(in, out);
out.close();
} static int N = 3000;
static class Task{ int n,m;
ArrayList<Integer> g[] = new ArrayList[N+10];
boolean can[][] = new boolean[N+10][N+10]; public void solve(InputReader in,PrintWriter out) {
for (int i = 1;i <= N;i++) {
g[i] = new ArrayList<Integer>();
}
n = in.nextInt(); m = in.nextInt();
for (int i = 1;i <= m;i++) {
int x,y;
x = in.nextInt();y = in.nextInt();
can[x][y] = true;
g[x].add(y);
}
long ans = 0;
for (int i = 1;i <= n;i++)
for (int j = 1;j <= n;j++)
if (i!=j) {
long numberofpath2 = 0;
for (int l = 0;l < (int)g[i].size();l++) {
int y = g[i].get(l);
if (can[y][j]) {
numberofpath2++;
}
}
ans = ans + numberofpath2*(numberofpath2-1)/2;
}
out.println(ans);
}
} static class InputReader{
public BufferedReader br;
public StringTokenizer tokenizer; public InputReader(InputStream ins) {
br = new BufferedReader(new InputStreamReader(ins));
tokenizer = null;
} public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.readLine());
}catch(IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
} public int nextInt() {
return Integer.parseInt(next());
}
}
}

【Codeforces 489D】Unbearable Controversy of Being的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  3. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  4. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  5. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  6. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  7. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

  8. 【Codeforces 670C】 Cinema

    [题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...

  9. 【codeforces 515D】Drazil and Tiles

    [题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...

随机推荐

  1. Linux中的LVM

    逻辑卷管理器,通过将另外一个硬盘上的分区加到已有文件系统,来动态地向已有文件系统添加空间的方法. 逻辑卷管理的核心是处理安装在系统上的硬盘分区.在逻辑卷管理的世界里,硬盘称作物理卷(Physical ...

  2. bzoj 1233: [Usaco2009Open]干草堆tower【dp+单调栈】

    参考:https://www.cnblogs.com/N-C-Derek/archive/2012/07/11/usaco_09_open_tower.html 虽然长得很像斜率优化,但是应该不算-- ...

  3. C#结构体+结构体与类的区别

    C# 结构(Struct) 在 C# 中,结构是值类型数据结构.它使得一个单一变量可以存储各种数据类型的相关数据.struct 关键字用于创建结构. C# 结构的特点 您已经用了一个简单的名为 Boo ...

  4. Android 性能优化(26)*性能工具之「Batterystats,Battery Historian」Batterystats & Battery Historian Walkthrough

    Batterystats & Battery Historian Walkthrough Working with Batterystats & Battery Historian B ...

  5. Windows 7上安装Microsoft Loopback Adapter(微软环回网卡)

    Oracle 安装过程中,先决条件检查遇到如下错误: 正在检查网络配置要求...  检查完成.此次检查的总体结果为: 失败 <<<<  问题: 安装检测到系统的主 IP 地址是 ...

  6. [转]mysql update操作

    转自:http://www.cnblogs.com/ggjucheng/archive/2012/11/06/2756392.html update语法 Single-table语法: UPDATE ...

  7. PostgreSQL与MySQL比较

    特性 MySQL PostgreSQL 实例 通过执行 MySQL 命令(mysqld)启动实例.一个实例可以管理一个或多个数据库.一台服务器可以运行多个 mysqld 实例.一个实例管理器可以监视 ...

  8. Scala-基础-数组(1)

    import junit.framework.TestCase import scala.collection.mutable.ArrayBuffer; //数组(1) //知识点-定义数组,变长数组 ...

  9. 利用eclipse调试JDK源码

    先看效果图 综合网上各种教程,总结如下 新建 D:/jdk/src .D:/jdk/debug 目录 src存放源码 debug存放编译结果 将 %JAVA_HOME%/src.zip 解压到 D:/ ...

  10. TensorFlow车牌识别实践(1)

    本文对公开的文章进行验证,从环境搭建到运行到结果分析. 1,文章:基于TensorFlow的车牌号识别系统 文章(译文) http://www.cnblogs.com/Jsmile2017/p/680 ...