传送门

Counting Stars

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 358    Accepted Submission(s): 90

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
Source
2017ACM/ICPC广西邀请赛-重现赛(感谢广西大学)
Recommend
liuyiding
题意:规定V=(A,B,C,D) and E=(AB,BC,CD,DA,AC)这种图算一种。给你一副图问有多少种。
分析:仔细分析一张这种图其实是两个三元环共用一条边得到,如果我能计算对边有多少条,那么我就能得出最后的答案。
我们考虑在求出三元环的过程中标记一下每条边有几个对点,最后算一下总数即可。
//china no.1
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <vector>
#include <iostream>
#include <string>
#include <map>
#include <stack>
#include <cstring>
#include <queue>
#include <list>
#include <stdio.h>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <cctype>
#include <sstream>
#include <functional>
#include <stdlib.h>
#include <time.h>
#include <bitset>
using namespace std;#define pi acos(-1)
#define PI acos(-1)
#define endl '\n'
#define srand() srand(time(0));
#define me(x,y) memset(x,y,sizeof(x));
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)
#define close() ios::sync_with_stdio(0); cin.tie(0);
#define FOR(x,n,i) for(int i=x;i<=n;i++)
#define FOr(x,n,i) for(int i=x;i<n;i++)
#define fOR(n,x,i) for(int i=n;i>=x;i--)
#define fOr(n,x,i) for(int i=n;i>x;i--)
#define W while
#define sgn(x) ((x) < 0 ? -1 : (x) > 0)
#define bug printf("***********\n");
#define db double
#define ll long long
#define mp make_pair
#define pb push_back
typedef long long LL;
const int INF=0x3f3f3f3f;
const LL LINF=0x3f3f3f3f3f3f3f3fLL;
const int dx[]={-1,0,1,0,1,-1,-1,1};
const int dy[]={0,1,0,-1,-1,1,-1,1};
const int maxn=1e3+10;
const int maxx=1e5+100;
const double EPS=1e-8;
const double eps=1e-8;
const int mod=1e9+7;
template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}
template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}
template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}
template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}
template <class T>
inline bool scan_d(T &ret){char c;int sgn;if (c = getchar(), c == EOF){return 0;}
while (c != '-' && (c < '0' || c > '9')){c = getchar();}sgn = (c == '-') ? -1 : 1;ret = (c == '-') ? 0 : (c - '0');
while (c = getchar(), c >= '0' && c <= '9'){ret = ret * 10 + (c - '0');}ret *= sgn;return 1;}inline bool scan_lf(double &num){char in;double Dec=0.1;bool IsN=false,IsD=false;in=getchar();if(in==EOF) return false;
while(in!='-'&&in!='.'&&(in<'0'||in>'9'))in=getchar();if(in=='-'){IsN=true;num=0;}else if(in=='.'){IsD=true;num=0;}
else num=in-'0';if(!IsD){while(in=getchar(),in>='0'&&in<='9'){num*=10;num+=in-'0';}}
if(in!='.'){if(IsN) num=-num;return true;}else{while(in=getchar(),in>='0'&&in<='9'){num+=Dec*(in-'0');Dec*=0.1;}}
if(IsN) num=-num;return true;}void Out(LL a){if(a < 0) { putchar('-'); a = -a; }if(a >= 10) Out(a / 10);putchar(a % 10 + '0');}
void print(LL a){ Out(a),puts("");}
//freopen( "in.txt" , "r" , stdin );
//freopen( "data.txt" , "w" , stdout );
//cerr << "run time is " << clock() << endl;int n,m;
vector<int>G[maxx];
int vis[maxx],link[maxx];
int main()
{W(~scanf("%d%d",&n,&m)){int u,v;me(vis,0);me(link,-1);int limit=ceil(sqrt(m));FOR(1,m,i){scan_d(u),scan_d(v);G[u].pb(v);G[v].pb(u);}FOR(1,n,i)sort(G[i].begin(),G[i].end());LL ans=0;FOR(1,n,i){vis[i]=1;for(int y:G[i]) link[y]=i;for(int y:G[i]){if(vis[y]) continue;LL cnt=0;if(G[y].size()<=limit){for(int z:G[y]){if(link[z]==i) cnt++;}}else{for(int z:G[i]){if(z!=y,binary_search(G[z].begin(),G[z].end(),y))cnt++;}}ans+=cnt*(cnt-1)/2;}}print(ans);FOR(1,n,i)G[i].clear();}
}
E=(AB,BC,CD,DA,AC)E=(AB,BC,CD,DA,AC)E=(AB,BC,CD,DA,AC)E=(AB,BC,CD,DA,AC)

E=(AB,BC,CD,DA,AC)问我饿

hdu 6184 三元环数目相关推荐

  1. 【HDU - 6184】Counting Stars(三元环计数,二分,优化暴力,O(m*sqrt(m)),图论)

    题干: Little A is an astronomy lover, and he has found that the sky was so beautiful! So he is countin ...

  2. HDU - 6184 Counting Stars(思维+三元环)

    题目链接:点击查看 题目大意:给出一个 nnn 个点 mmm 条边组成的无向图,问图中有多少个"三元环对","三元环对"指的是两个三元环共用了一条边 题目分析: ...

  3. HDU 6184 2017广西邀请赛:Counting Stars(三元环)

    题意: n个点m条边的无向图,问有多少个A-structure 其中A-structure满足V=(A,B,C,D) && E=(AB,BC,CD,DA,AC) 可以看出A-struc ...

  4. 牛客挑战赛51 E NIT的gcd(欧拉反演,建图优化,三元环计数)

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Problem 给你一个正整数 nnn. 请你输出 ∑i=1n∑j=1n∑k=1ngcd⁡(i,j)g ...

  5. P4619 [SDOI2018]旧试题(莫比乌斯反演,建图优化三重枚举,三元环计数,神仙好题,超级清晰易懂)

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 P4619 [SDOI2018]旧试题(莫比乌斯反演,三元环计数) Problem 计算: ∑i=1A ...

  6. Codeforces Gym 100342J Problem J. Triatrip 求三元环的数量 bitset

    Problem J. Triatrip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...

  7. 洛谷 - P1989 无向图三元环计数(思维建图)

    题目链接:点击查看 题目大意:给出一个 nnn 个点 mmm 条边组成的无向图,求三元环的个数 题目分析:对于原图建新图,对于原来的每条边来说 如果度数不同,度数小的点指向度数大的点 如果度数相同,编 ...

  8. HDU6184【Counting Stars】(三元环计数)

    题面 传送门 给出一张无向图,求 \(4\) 个点构成两个有公共边的三元环的方案数. 题解 orz余奶奶,orz zzk 首先,如果我们知道经过每条边的三元环个数\(cnt_i\),那么答案就是\(\ ...

  9. Gym - 102001K Boomerangs 构造 + 三元环

    传送门 文章目录 题意: 思路: 题意: 给你一张nnn个点mmm条边的简单图,让你找出尽可能多的三元环,要求每个三元环都不能共边,输出三元环数量和具体是那个. n,m≤1e5n,m\le1e5n,m ...

  10. P1989 无向图三元环计数 思维 + 建图

    传送门 文章目录 题意: 思路: 题意: 统计无向图中三元环的个数. 思路: 很明显有一种暴力的方法,就是枚举每条边,让后再跑两个点的所有边,可以卡到复杂度O(m2)O(m^2)O(m2). 我们可以 ...

最新文章

  1. tensorflow2.0 RNN文本预测
  2. oracle数据库可以存图片吗,如何往数据库(Oracle)里存储图片和文件
  3. linux的简单面试题,收集的一些简单的UNIX/Linux面试题
  4. KDD 18论文解读 | 斯坦福大学提出全新网络嵌入方法 — GraphWave
  5. 曾经迷茫的起点,多年后终于明白了(续)
  6. TypeScript class 构造函数和成员的初始化顺序
  7. linux安装java jdk_Linux安装JDK详细步骤
  8. (整理)C/C++野指针
  9. 【2021牛客暑期多校训练营5】Double Strings(二维字符串dp)
  10. LabelSmooth
  11. 银行业务队列简单模拟Java程序设计_PTA 数据结构 银行业务队列简单模拟
  12. 新一配:终于有人发声:靠炒股到底能不能发财?此文无价,很短很深
  13. opencv小案例 --- 证件照背景替换
  14. Cookie中path总结
  15. itools3.0服务器维护,苹果设备管理哪家强?iTools3.0 完胜 iTunes
  16. html编写购物网站页面练习(一)
  17. IDEA解决crtl+space与搜狗输入法冲突
  18. 项目管理PMP好考吗,没有经验?
  19. 青云QingCloud与陕中二院联手打造智慧医院范本
  20. 基于FPGA数字示波器的显示

热门文章

  1. 干货分享:如何把APP软文推广做到好
  2. @永和:为自己编码 --- 开源中国众包平台上线
  3. 中小板上市要走那些流程
  4. 保研推免经历经验分享——2018北大软微、北航计算机、南大计算机夏令营保研经历
  5. GUI-Guider中文手册
  6. adrunio蜂鸣器音乐(天空之城)c调
  7. 三运放差分放大电路分析_三运放差动放大电路
  8. 时钟芯片S35390A
  9. 手把手教你搭建一个你自己的语音合成系统
  10. 对象存储oss挂载工具ossfs的使用