首页 技术 正文
技术 2022年11月14日
0 收藏 418 点赞 4,747 浏览 2135 个字

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 InputThere 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 OutputFor each test case, just output one integer–the number
of different “A-structure”s in one line. Sample Input4 51 22 33 44 11 34 61 22 33 44 11 32 4 Sample Output16

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

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 ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,083
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,558
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,407
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,180
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,816
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,899