> 웹 프론트엔드 > HTML 튜토리얼 > Codeforces Round #277.5 (Div. 2)-D_html/css_WEB-ITnose

Codeforces Round #277.5 (Div. 2)-D_html/css_WEB-ITnose

WBOY
풀어 주다: 2016-06-24 11:53:55
원래의
1048명이 탐색했습니다.

题意:求该死的菱形数目。直接枚举两端的点,平均意义每个点连接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 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 scanf int ans="0;" for i="1;i<=n;i++)" j="1;j<=n;j++)" if r="0;" e="first[i];~e;e=nex[e])" printf return>  <br>  <br>  <p></p>  <p><br> </p>  <p></p>  <p class="sycode">   </p>
<p class="sycode">    </p>
<p class="sycode">     </p>
<p class="sycode">      </p>
<p class="sycode">       </p>
<p class="sycode">        </p>
<p class="sycode">         D. Unbearable Controversy of Being        </p>        <p class="sycode">         </p>
<p class="sycode">          time limit per test         </p> 1 second                <p class="sycode">         </p>
<p class="sycode">          memory limit per test         </p> 256 megabytes                <p class="sycode">         </p>
<p class="sycode">          input         </p> standard input                <p class="sycode">         </p>
<p class="sycode">          output         </p> standard output                      <p class="sycode">        </p>
<p> 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!</p>        <p> 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:</p>                <p> 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.</p>        <p> 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.</p>        <p> When rhombi are compared, the order of intersections b and d doesn't matter.</p>              <p class="sycode">        </p>
<p class="sycode">         Input        </p>        <p> 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.</p>        <p> It is not guaranteed that you can get from any intersection to any other one.</p>              <p class="sycode">        </p>
<p class="sycode">         Output        </p>        <p> Print the required number of "damn rhombi".</p>              <p class="sycode">        </p>
<p class="sycode">         Sample test(s)        </p>        <p class="sycode">         </p>
<p class="sycode">          </p>
<p class="sycode">           input          </p>          <pre style="代码" class="precsshei">5 41 22 31 44 3
로그인 후 복사

output

input

4 121 21 31 42 12 32 43 13 23 44 14 24 3
로그인 후 복사

output

12
로그인 후 복사



원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿