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. Linux中的mysql指令

    如何启动/停止/重启MySQL一.启动方式1.使用 service 启动:service mysqld start2.使用 mysqld 脚本启动:/etc/inint.d/mysqld start3 ...

  2. UnityShader学习笔记1 — — 入门知识整理

    注:资料整理自<Unity Shader入门精要>一书 一.渲染流程概念阶段:  应用阶段:(1)准备好场景数据:(如摄像机位置,物体以及光源等)   (2)粗粒度剔除(Culling): ...

  3. ThreadPoolExecutor 使用说明

    它是一个ExecutorService,使用线程池中的线程执行提交的任务.通常我们使用Executors框架,定义使用. 线程池主要用来解决两类问题:通过缓存一定数量的可用线程,避免频繁的线程创建,销 ...

  4. Java字符串连接操作的性能问题

    首先,看一段实验程序: package com.test; class StringTest { public static void main(String[] args) { long start ...

  5. kubernetes高可用设计-master节点和kubectl

    部署master 节点 上一遍是CA证书和etcd的部署,这一篇继续搭建k8s,废话不多说.开始部署. kubernetes master 节点包含的组件有: kube-apiserver kube- ...

  6. 学习笔记 | Set

    目录 Set Set 前言 不会数据结构选手 当几乎没写过什么数据结构的菜鸡遇上了毒瘤的splay和treap 时间正一点一点地被续走TAT 听说set有时候可以替代treap和splay 那么菜鸡L ...

  7. 比较语义分割的几种结构:FCN,UNET,SegNet,PSPNet和Deeplab

    简介 语义分割:给图像的每个像素点标注类别.通常认为这个类别与邻近像素类别有关,同时也和这个像素点归属的整体类别有关.利用图像分类的网络结构,可以利用不同层次的特征向量来满足判定需求.现有算法的主要区 ...

  8. Erlang数据类型的表示和实现(2)——Eterm 和立即数

    Erlang 数据类型的内部表示和实现 Erlang 中的变量在绑定之前是自由的,非绑定变量可以绑定一次任意类型的数据.为了支持这种类型系统,Erlang 虚拟机采用的实现方法是用一个带有标签的机器字 ...

  9. Python列表解析

    列表解析 根据已有列表,高效创建新列表的方式. 列表解析是Python迭代机制的一种应用,它常用于实现创建新的列表,因此用在[]中. 语法: [expression for iter_val in i ...

  10. Python之并发编程-多线程

    目录 一.threading模块介绍二.使用说明三.进一步介绍(守护线程,锁(互斥锁.递归锁),信号量,队列,event,condition,定时器) 1.守护线程 2.锁(互斥锁.递归锁) 3.信号 ...