#include#include

亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

【cf489】D. Unbearable Controversy of Being

系統(tǒng) 1905 0

http://codeforces.com/contest/489/problem/D

很顯然,我們只需要找對于每個點(diǎn)能到達(dá)的深度為3的點(diǎn)的路徑的數(shù)量,那么對于一個深度為3的點(diǎn),如果有a種方式到達(dá),那么有方案數(shù)(a-1+1)*(a-1)/2

可是我用dfs找路徑就tle了QAQ

于是orz別人的代碼,,,,是暴力。。。。。。。。。。。。。。。。。。。。。。。。直接兩重循環(huán)orz

      #include <cstdio>

#include <cstring>

#include <cmath>

#include <string>

#include <iostream>

#include <algorithm>

#include <queue>

#include <set>

#include <map>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i=0; i<(n); ++i)

#define for1(i,a,n) for(int i=(a);i<=(n);++i)

#define for2(i,a,n) for(int i=(a);i<(n);++i)

#define for3(i,a,n) for(int i=(a);i>=(n);--i)

#define for4(i,a,n) for(int i=(a);i>(n);--i)

#define CC(i,a) memset(i,a,sizeof(i))

#define read(a) a=getint()

#define print(a) printf("%d", a)

#define dbg(x) cout << (#x) << " = " << (x) << endl

#define error(x) (!(x)?puts("error"):0)

#define rdm(x, i) for(int i=ihead[x]; i; i=e[i].next)

inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }

const int N=3005;

struct dat { int to, next; }e[N*10];

int cnt, vis[N], c[N], n, m, ihead[N];

void add(int u, int v) { e[++cnt].next=ihead[u]; ihead[u]=cnt; e[cnt].to=v; }

void bfs(int x, int dep) {

	rdm(x, i) {

		int y=e[i].to;

		rdm(y, j) {

			int z=e[j].to;

			if(x==z) continue;

			++c[z];

		}

	}

}

ll ans;

int main() {

	read(n); read(m);

	for1(i, 1, m) { int u=getint(), v=getint(); add(u, v); }

	for1(i, 1, n) {

		for1(j, 1, n) vis[j]=0, c[j]=0;

		bfs(i, 1);

		//for1(j, 1, n) cout << c[j] << ' '; cout << endl;

		for1(j, 1, n) if(c[j]>=2) {

			--c[j];

			ans+=(ll)(c[j]+1)*c[j]/2;

		}

	}

	printf("%I64d\n", ans);

	return 0;

}


    

?


?

?

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?a,?b,?c?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:

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

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?n,?m?(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
        

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


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 岛国三级视频 | 毛片免费观看的视频 | 国产成人综合久久 | 欧美激情精品久久久久久久久久 | 九九热视频这里只有精品 | 久久影院在线观看 | 日韩精品视频观看 | 精品乱码一区二区三区在线 | 日本成人一区二区 | 久草视频新 | 久久婷婷综合中文字幕 | 亚州毛色毛片免费观看 | 三级性生活视频 | 婷婷综合亚洲 | 中国一级毛片aaa片 中国一级毛片录像 | 91国语精品自产拍在线观看一 | 四虎影视免费在线观看 | 亚洲国产精品久久久久久 | 97se综合 | 波多野结衣中文字幕一区二区三区 | 日本高清视频www夜色资源网 | 看全色黄大色大片免费视频 | 国产毛片精品 | 欧美日韩国产高清精卡 | 国产91精品一区二区麻豆网站 | 免费超爽大片黄网站 | 久久久精品久久久久特色影视 | 99久久精品免费看国产免费 | 三级aa久久 | 欧美激情一区二区三级高清视频 | 亚洲免费福利视频 | 成人免费一级片 | 四虎影院免费 | 日韩a毛片 | 色老头成人免费视频天天综合 | 欧美精品成人一区二区在线观看 | 国产91在线 | 欧美 | 国产97在线 | 亚洲 | 欧美日韩另类综合 | 亚洲一级毛片 | 国产99在线播放免费 |