hdu 6184 三元环数目
来源:互联网 发布:淘宝如何刷流量 编辑:程序博客网 时间:2024/05/17 06:02
传送门
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.
IfV=(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 .
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
It is defined that "A-structure"
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
For each test case, there are 2 positive integers n and m in the first line.
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.
Output
For each test case, just output one integer--the number of different "A-structure"s in one line.
Sample Input
4 51 22 33 44 11 34 61 22 33 44 11 32 4
Sample Output
16
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_backtypedef 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(); }}
阅读全文
0 0
- hdu 6184 三元环数目
- HDU 6184 求三元环
- HDU 6184 && 2017广西邀请赛:Counting Stars(三元环)
- 【m*sqrt(m)暴力三元环】hdu 6184
- HDU-6184 (无向图三元环计数)
- HDU 6184&& 2017广西邀请赛 Counting Stars(三元环计数)
- 【2017广西邀请赛】hdu 6184 Counting Stars 三元环+set
- HDU 6184 Counting Star(找三元环)
- POJ 6184 【三元环 +分治】
- hdu 6184 Counting Stars(求无向图的三元环数量)
- HDU 6184 Counting Stars(无向图三元环计数)
- hdu 6184 Counting Stars(求无向图三元环)
- HDU 3939 毕达哥拉斯三元组
- HDU 2574 素数因子数目
- hdu 4587 tarjian求割点数目
- 三元环的个数
- hdu6184(三元环计数)
- [竞赛图三元环存在性判断] HDU 4324 Triangle LOVE
- python中使用字符串
- 学生信息管理系统之错误百出2
- Android -Adapter深入理解与优化
- vue+webpack+bootstrap使用
- crypt.7. 如何共享秘密
- hdu 6184 三元环数目
- 协议
- velocity中for循环中使用VelocityCount
- Instruments 检测内存的使用
- nasm汇编程序例程got
- 索引优先队列
- windows下搭建poco库
- upc4041:简单的图论?&&湖南省第十一届大学生计算机程序设计竞赛
- 今天网络专业课的一点总结