Problem Description

Little A is an astronomy lover, and he has found that the sky was so beautiful!

So he is counting stars now!

There are n stars in the sky, and little A has connected them by m non-directional edges.

It is guranteed that no edges connect one star with itself, and every two edges connect different pairs of stars.

Now little A wants to know that how many different "A-Structure"s are there in the sky, can you help him?

An "A-structure" can be seen as a non-directional subgraph G, with a set of four nodes V and a set of five edges E.

If V=(A,B,C,D) and E=(AB,BC,CD,DA,AC), we call G as an "A-structure".

It is defined that "A-structure" G1=V1+E1 and G2=V2+E2 are same only in the condition that V1=V2 and E1=E2.

Input

There are no more than 300 test cases.

For each test case, there are 2 positive integers n and m in the first line.

2≤n≤105, 1≤m≤min(2×105,n(n−1)2)

And then m lines follow, in each line there are two positive integers u and v, describing that this edge connects node u and node v.

1≤u,v≤n

∑n≤3×105,∑m≤6×105

Output

For each test case, just output one integer--the number of different "A-structure"s in one line.

Sample Input

4 5

1 2

2 3

3 4

4 1

1 3

4 6

1 2

2 3

3 4

4 1

1 3

2 4

Sample Output

1

6

Description(CHN)

给你一个图,找有多少个

Solution

三元环裸题

把每条边属于多少个三元环求出来,然后对于每条边算贡献就好了

如何求三元环,这是某道题目的solution的一部分

  1. #include<bits/stdc++.h>
  2. #define ui unsigned int
  3. #define ll long long
  4. #define db double
  5. #define ld long double
  6. #define ull unsigned long long
  7. const int MAXN=300000+10,MAXM=600000+10;
  8. int n,m,e,beg[MAXN],nex[MAXM<<1],to[MAXM<<1],cnt[MAXN],in[MAXN],arv[MAXN],pres[MAXN],clk;
  9. struct node{
  10. int u,v;
  11. };
  12. node side[MAXN];
  13. ll ans=0;
  14. template<typename T> inline void read(T &x)
  15. {
  16. T data=0,w=1;
  17. char ch=0;
  18. while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
  19. if(ch=='-')w=-1,ch=getchar();
  20. while(ch>='0'&&ch<='9')data=((T)data<<3)+((T)data<<1)+(ch^'0'),ch=getchar();
  21. x=data*w;
  22. }
  23. template<typename T> inline void write(T x,char ch='\0')
  24. {
  25. if(x<0)putchar('-'),x=-x;
  26. if(x>9)write(x/10);
  27. putchar(x%10+'0');
  28. if(ch!='\0')putchar(ch);
  29. }
  30. template<typename T> inline void chkmin(T &x,T y){x=(y<x?y:x);}
  31. template<typename T> inline void chkmax(T &x,T y){x=(y>x?y:x);}
  32. template<typename T> inline T min(T x,T y){return x<y?x:y;}
  33. template<typename T> inline T max(T x,T y){return x>y?x:y;}
  34. inline void insert(int x,int y)
  35. {
  36. to[++e]=y;
  37. nex[e]=beg[x];
  38. beg[x]=e;
  39. }
  40. int main()
  41. {
  42. while(scanf("%d%d",&n,&m)!=EOF)
  43. {
  44. e=ans=0;clk=1;
  45. for(register int i=1;i<=n;++i)beg[i]=in[i]=arv[i]=pres[i]=0;
  46. for(register int i=1,u,v;i<=m;++i)
  47. {
  48. cnt[i]=0;
  49. read(u);read(v);
  50. side[i].u=u;side[i].v=v;
  51. in[u]++;in[v]++;
  52. }
  53. for(register int i=1,u,v;i<=m;++i)
  54. {
  55. u=side[i].u,v=side[i].v;
  56. if(in[v]>in[u]||(in[v]==in[u]&&v>u))insert(u,v);
  57. else insert(v,u);
  58. }
  59. for(register int i=1,u,v;i<=m;++i,++clk)
  60. {
  61. u=side[i].u,v=side[i].v;
  62. for(register int j=beg[u];j;j=nex[j])arv[to[j]]=clk,pres[to[j]]=j;
  63. for(register int j=beg[v];j;j=nex[j])
  64. if(arv[to[j]]==clk)cnt[i]++,cnt[j]++,cnt[pres[to[j]]]++;
  65. }
  66. for(register int i=1;i<=m;++i)ans+=1ll*cnt[i]*(cnt[i]-1)/2;
  67. write(ans,'\n');
  68. }
  69. return 0;
  70. }

【刷题】HDU 6184 Counting Stars的更多相关文章

  1. [hdu 6184 Counting Stars(三元环计数)

    hdu 6184 Counting Stars(三元环计数) 题意: 给一张n个点m条边的无向图,问有多少个\(A-structure\) 其中\(A-structure\)满足\(V=(A,B,C, ...

  2. HDU 6184 Counting Stars

    Problem Description Little A is an astronomy lover, and he has found that the sky was so beautiful!S ...

  3. HDU 6184 Counting Stars 经典三元环计数

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6184 题意: n个点m条边的无向图,问有多少个A-structure 其中A-structure满足V ...

  4. HDU 自动刷题机 Auto AC (轻轻松松进入HDU首页)

    前言: 在写这篇文章之前,首先感谢给我思路以及帮助过我的学长们 以下4篇博客都是学长原创,其中有很多有用的,值得学习的东西,希望能够帮到大家! 1.手把手教你用C++ 写ACM自动刷题神器(冲入HDU ...

  5. 手把手教你用C++ 写ACM自动刷题神器(冲入HDU首页)

    转载注明原地址:http://blog.csdn.net/nk_test/article/details/49497017 少年,作为苦练ACM,通宵刷题的你 是不是想着有一天能够荣登各大OJ榜首,俯 ...

  6. 教你用python写:HDU刷题神器

    声明:本文以学习为目的,请不要影响他人正常判题 HDU刷题神器,早已被前辈们做出来了,不过没有见过用python写的.大一的时候见识了学长写这个,当时还是一脸懵逼,只知道这玩意儿好屌-.时隔一年,决定 ...

  7. 【刷题】HDU 2222 Keywords Search

    Problem Description In the modern time, Search engine came into the life of everybody like Google, B ...

  8. 三元环HDU 6184

    HDU - 6184 C - Counting Stars 题目大意:有n个点,m条边,问有一共有多少个‘structure’也就是满足V=(A,B,C,D) and E=(AB,BC,CD,DA,A ...

  9. hdu 5862 Counting Intersections

    传送门:hdu 5862 Counting Intersections 题意:对于平行于坐标轴的n条线段,求两两相交的线段对有多少个,包括十,T型 官方题解:由于数据限制,只有竖向与横向的线段才会产生 ...

随机推荐

  1. xgboost算法教程(两种使用方法)

    标签: xgboost 作者:炼己者 ------ 欢迎大家访问我的简书以及我的博客 本博客所有内容以学习.研究和分享为主,如需转载,请联系本人,标明作者和出处,并且是非商业用途,谢谢! ------ ...

  2. iOS 关于在提交了APP等待审核之后,发现小Bug需要再提一个版本的说明

    昨天晚上加班到深夜终于将APP推上去,今天早上过来再测试一遍的时候,发现需要一个小调整.而此时应用的状态是正在等待审核,随手记录一下这种情况下,提交一个新版本的做法,有需要的可以参考一下. 01-进入 ...

  3. Maven学习(七)-----Maven添加远程仓库

    Maven添加远程仓库 默认情况下,Maven从Maven中央仓库下载所有依赖关系.但是,有些库丢失在中央存储库,只有在Java.net或JBoss的储存库远程仓库中能找到. 1. Java.net资 ...

  4. Nginx高性能优化

    #Nginx配置文件优化 worker_processes ; # nginx进程数,建议按照cpu数目来指定,一般为它的倍数. worker_cpu_affinity ; # 为每个进程分配CPU的 ...

  5. 在进行分布式框架搭建的过程中,出现问题advised by org.springframework.transaction.interceptor.TransactionInterceptor.invoke(org.aopalliance.intercept.MethodInvocation)?

    今天在进行宜立方商城,进行文件配置的时间,遇到如下的问题,问题是:advised by org.springframework.transaction.interceptor.TransactionI ...

  6. hibernate.hbm.xml文件配置入门小结(1)

    在Hibernate中,各表的映射文件xxx.hbm.xml可以通过工具生成,例如在使用MyEclipse开发时,它提供了自动生成映射文件的工具. hibernate.hbm.xml文件的基本结构如下 ...

  7. DotNetOpenAuth Part 1 : Authorization 验证服务实现及关键源码解析

    DotNetOpenAuth 是 .Net 环境下OAuth 开源实现框架.基于此,可以方便的实现 OAuth 验证(Authorization)服务.资源(Resource)服务.针对 DotNet ...

  8. 第三次ScrumMeeting博客

    第三次ScrumMeeting博客 本次会议于10月27日(五)22时整在3公寓725房间召开,持续10分钟. 与会人员:刘畅.方科栋.窦鑫泽.张安澜. 1. 每个人的工作(有Issue的内容和链接) ...

  9. Spark SQL、DataFrame和Dataset——转载

    转载自:  Spark SQL.DataFrame和Datase

  10. 项目进行ing

    1.我们的看板 2.立行会议 (1)照片 (2)时间:每天20:00 (3)地点:学校研发中心会议室 3.看板进展: 已有6个任务被移到Check Out栏中,详细情况如下: 梁植淋:构建项目架构,封 ...