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

题意:给定一张无向图,求有公共边的三元环对数。

Solution:

  三元环裸题。

  直接三元环计数,然后开一个桶记录一下每条边在多少个三元环中出现,最后的答案就是$\sum_\limits{i=1}^{i\leq m}{\frac{tot[i]*(tot[i]-1)}{2}}$。

代码:

/*Code by 520 -- 9.10*/
#include<iostream>
#include<cstdio>
#include<cstring>
#define il inline
#define ll long long
#define RE register
#define For(i,a,b) for(RE int (i)=(a);(i)<=(b);(i)++)
#define Bor(i,a,b) for(RE int (i)=(b);(i)>=(a);(i)--)
using namespace std;
const int N=,M=;
int n,m,to[M],net[M],h[N],cnt,tot[M],pre[N],vis[N],deg[N];
struct node{
int u,v;
}e[M];
ll ans; il void add(int u,int v){to[++cnt]=v,net[cnt]=h[u],h[u]=cnt;} int main(){
while(scanf("%d%d",&n,&m)==){
For(i,,m) scanf("%d%d",&e[i].u,&e[i].v),deg[e[i].u]++,deg[e[i].v]++;
For(i,,m) {
RE int u=e[i].u,v=e[i].v;
if(deg[u]<deg[v]||deg[u]==deg[v]&&u>v) swap(u,v);
add(u,v);
}
For(u,,n){
for(RE int i=h[u];i;i=net[i]) vis[to[i]]=u,pre[to[i]]=i;
for(RE int i=h[u];i;i=net[i]){
RE int v=to[i];
for(RE int j=h[v];j;j=net[j]){
RE int w=to[j];
if(vis[w]==u) ++tot[i],++tot[j],++tot[pre[w]];
}
}
}
For(i,,cnt) ans+=1ll*tot[i]*(tot[i]-)/;
printf("%lld\n",ans);
memset(h,,sizeof(h)),memset(deg,,sizeof(deg)),
memset(tot,,sizeof(tot)),memset(pre,,sizeof(pre)),
memset(vis,,sizeof(vis)),cnt=,ans=;
}
return ;
}

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! ...

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

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

  4. 三元环HDU 6184

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

  5. XidianOJ 1177 Counting Stars

    题目描述 "But baby, I've been, I've been praying hard,     Said, no more counting dollars     We'll ...

  6. hdu 5862 Counting Intersections

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

  7. HDU 5862 Counting Intersections(离散化+树状数组)

    HDU 5862 Counting Intersections(离散化+树状数组) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 D ...

  8. Counting Stars

    Counting Stars 题目链接:http://acm.xidian.edu.cn/problem.php?id=1177 离线+一维树状数组 一眼扫过去:平面区间求和,1e6的数据范围,这要h ...

  9. Hdu 5862 Counting Intersections(有n条线段,每一条线段都是平行于x轴或者y轴,问有多少个交点+树状数组区间求和单点跟新)

    传送门:Hdu 5862 Counting Intersections 题意:有n条线段,每一条线段都是平行于x轴或者y轴,问有多少个交点 分析: 基本的操作流程是:先将所有的线段按照横树坐标x按小的 ...

随机推荐

  1. Asp.Net Form验证不通过,重复登录(.net4,4.5form验证兼容性问题)

    问题产生根源: 当然,其实应该需要保持线上所有机器环境一致!可是,写了一个小程序.使用的是4.5,aysnc/await实在太好用了,真心不想把代码修改回去. so,动了念头,在这台服务器上装个4.5 ...

  2. Ubuntu18.04安装Python3.6.8

    Ubuntu18.04预装了Python3.6.5 终于不再预装Python2.7了 但是系统预装的Python分散安装在各个目录里 以后改起来非常不方便 所以本次安装Python3.6.8 Pyth ...

  3. Linux命令的那些事(二)

    回顾Linux(一) 学习了以下命令: mkdir/rmdir/ls/rm/pwd/cd/touch/tree/man/--help 想具体了解请看上一篇文章跳转 在Linux中推荐大家使用subli ...

  4. [C++]模板类和模板函数

    参考: C++ 中模板使用详解 C++模板详解 概念 为了避免因重载函数定义不全面而带来的调用错误,引入了模板机制 定义 模板是C++支持参数化多态的工具,使用模板可以使用户为类或者函数声明一种一般模 ...

  5. yocto-sumo源码解析(七): BitBakeServer

    1. 创建域套接字,管道以及锁: self.configuration = configuration self.featureset = featureset self.sockname = soc ...

  6. 简介几种系统调用函数:write、read、open、close、ioctl

    在 Linux 中,一切(或几乎一切)都是文件,因此,文件操作在 Linux 中是十分重要的,为此,Linux 系统直接提供了一些函数用于对文件和设备进行访问和控制,这些函数被称为系统调用(sysca ...

  7. NO.4:自学python之路------内置方法、装饰器、迭代器

    引言 是时候开始新的Python学习了,最近要考英语,可能不会周更,但是尽量吧. 正文 内置方法 Python提供给了使用者很多内置方法,可以便于编程使用.这里就来挑选其中大部分的内置方法进行解释其用 ...

  8. PHP 伪协议

    1.file:// file://用于访问本地文件系统,不受allow_url_fopen影响 <?php include($_GET['file']); ?> 2.http:// GET ...

  9. python3 通过qq邮箱定时发送邮件

    下面的代码为了每天定时发送监控邮件,监控什么呢?监控当天redis队列中是否有没有消费的数据,和当天mysql中新增的数据量 # -*- coding:utf-8 -*- from common.re ...

  10. 利用Python编写Windows恶意代码!自娱自乐!勿用于非法用途!

    本文主要展示的是通过使用python和PyInstaller来构建恶意软件的一些poc. 利用Python编写Windows恶意代码!自娱自乐!勿用于非法用途!众所周知的,恶意软件如果影响到了他人的生 ...