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

【题意】

让你找到(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. SQL 存储过程语句拼接愁人的时间类型

    http://www.cnblogs.com/yrup/p/4201329.html 解决方法: Select CONVERT(varchar(100), GETDATE(), 25): 2006-0 ...

  2. E20170609-ts

    algorithm n.算法 layout   n. 布局,安排,设计; 布置图,规划图; resource  n. 资源; 物力,财力; 办法; 智谋; partial adj. 部分的; 偏爱的; ...

  3. GG_Logs 日志类库封装使用说明

    3.6.GG_Logs 日志类库封装使用说明 GG_Logs类库项目,Nuget安装log4net 添加代码配置代码: [assembly: log4net.Config.XmlConfigurato ...

  4. event.target 属性返回哪个 DOM 元素触发了事件。

    <ul> <li>list <strong>item 1</strong></li> <li><span>list ...

  5. ACM_N皇后问题

    N皇后问题 Time Limit: 2000/1000ms (Java/Others) Problem Description: 在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不 ...

  6. Markdown基本语法学习

    Markdown是一种纯文本格式的标记语言.通过简单的标记语法,它可以使普通文本内容具有一定的格式. 创始人 John Gruber 的 Markdown 语法说明 Markdown 中文版语法说明 ...

  7. 【转】mysql中select用法

    转自:http://blog.sina.com.cn/s/blog_a74f39a201013c3b.html 1.选择所有的记录 select * from table_name; 其中*表示表中的 ...

  8. hihocoder offer收割编程练习赛13 D 骑士游历

    思路: 矩阵快速幂. 实现: #include <iostream> #include <cstdio> #include <vector> using names ...

  9. 42使用NanoPiM1Plus在Android4.4.2下的录音测试

    42使用NanoPiM1Plus在Android4.4.2下的录音测试 大文实验室/大文哥壹捌陆捌零陆捌捌陆捌贰21504965 AT qq.com完成时间:2017/12/5 17:51版本:V1. ...

  10. CentOS7上安装稻壳CMS

    CentOS7上安装稻壳CMS 1, 安装用途 为了给某公司建设一个小型网站,租用了一个阿里云ECS服务器,最基础的硬件配置,因此选择了CentOS7操作系统. 稻壳CMS(docCMS)源于深喉咙C ...