首页 > 其他分享 >2017ACM/ICPC广西邀请赛-重现赛(感谢广西大学)C - Counting Stars 暴力三元环

2017ACM/ICPC广西邀请赛-重现赛(感谢广西大学)C - Counting Stars 暴力三元环

时间:2023-04-24 23:03:06浏览次数:48  
标签:Counting int long ICPC maxn Stars ans include define

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

暴力找即可;

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<string>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
typedef long long ll;
using namespace std;
typedef unsigned long long int ull;
#define maxn 100005
#define ms(x) memset(x,0,sizeof(x))
#define Inf 0x7fffffff
#define inf 0x3f3f3f3f
const int mod = 1e9 + 7;
#define pi acos(-1.0)
#define pii pair<int,int>
#define eps 1e-5
#define pll pair<ll,ll>
#define lson 2*x
#define rson 2*x+1

long long  qupower(int a, int b) {
    long long  ans = 1;
    while (b) {
        if (b & 1)ans = ans * a;
        b >>= 1;
        a = a * a;
    }
    return ans;
}

inline int read() {
    int an = 0, x = 1; char c = getchar();
    while (c > '9' || c < '0') {
        if (c == '-') {
            x = -1; 
        }
        c = getchar();
    }
    while (c >= '0'&&c <= '9') {
        an = an * 10 + c - '0'; c = getchar();
    }
    return an * x;
}

vector<int>G[maxn];
set<ll>st;
int vis[maxn], lnk[maxn], ot[maxn];


int main() {
    ios::sync_with_stdio(false);
    int n, m;
    ll ans, sum;
    while (cin >> n >> m) {
        int i, j;
        ans = 0; sum = 0;
        int part = sqrt(m);

        for (i = 1; i <= n; i++)G[i].clear();
        ms(vis); st.clear(); ms(lnk); ms(ot);
        for (i = 0; i < m; i++) {
            int u, v;
            cin >> u >> v;
            G[u].push_back(v); ot[u]++;
            G[v].push_back(u); ot[v]++;
            st.insert((ll)u*n + v);
            st.insert((ll)v*n + u);
        }
        for (i = 1; i <= n; i++) {
            int x = i;
            vis[x] = 1;
            for (j = 0; j < G[x].size(); j++) {
                lnk[G[x][j]] = x;
            }

            for (j = 0; j < G[x].size(); j++) {
                sum = 0;
                int y = G[x][j];
                if (vis[y])continue;
                if (ot[y] <= part) {
                    for (int k = 0; k < G[y].size(); k++) {
                        if (lnk[G[y][k]] == x)sum++;
                    }
                }
                else {
                    for (int k = 0; k < G[x].size(); k++) {
                        int z = G[x][k];
                        if (st.find((ll)z*n + y) != st.end())sum++;
                    }
                }
                ans += 1ll*(sum - 1)*sum / 2;
            }
        }
        cout << ans << endl;
    }
}

标签:Counting,int,long,ICPC,maxn,Stars,ans,include,define
From: https://blog.51cto.com/u_15657999/6222000

相关文章

  • The 2017 ACM - ICPC Asia Ho Chi Minh City Regional Contest
    ThetunnelsofCuChiareanimmensenetworkofundergroundtunnelsconnectingroomslocatedintheCuChiDistrictofHoChiMinhCity.TheCuChitunnelswerethelocationofseveralmilitarycampaignsinthe1960s.Nowadays,itisapopulartouristdes......
  • Au Revoir, icpc
    AuRevoir,icpc——永别了,icpc今日天梯赛打得并不好,甚至没能进前三,赛后20s发现是某个细节写错了。具体是什么?问题:有一块\(n\timesm\)的海洋,上面有一些岛屿,此外还有一些宝藏。求岛屿个数和宝藏岛屿个数(四联通)。我写的是,首先将所有岛屿标为\(1\)(包括宝藏),然后求连......
  • Counting Rectangles UVA - 10574
    给出n个点。问选出4个点作为定点,能够组成多少个平行与坐标轴的矩形。 点按照x排序 n^2挑选出垂直x轴的线段,按照y1排序  #include<iostream>#include<cstring>#include<algorithm>#include<vector>usingnamespacestd;constintN=1e5;structT{ intx......
  • Counting
    CountingTypeRepetitionAllowed?Formular-permutationsNo$P_n^k=r!{n\choosek}$r-combinationsNo\(C_n^k={n\chooser}\)r-permutationsYes\(n^k\)r-combinationsYes$C_{n+k-1}^k={n+k-1\choosek}$r-combinationswit......
  • 菜鸟记录:c语言实现PAT甲级1004--Counting Leaves
    好消息:与上题的Emergency是同样的方法。坏消息:又错了&&c++真的比c方便太多太多。Afamilyhierarchyisusuallypresentedbyapedigreetree.Yourjobistocountthosefamilymemberswhohavenochild.InputSpecification:Eachinputfilecontainsonetest......
  • CF1816F Xor Counting - dp - 分治 -
    题目链接:https://codeforces.com/contest/1816/problem/F题解:一道有趣的题。首先发现\(m=1\)和\(m\geq3\)时结论是平凡的。\(m=1\)时结论显然,下面讨论一下\(m\geq3\)时:首先可以构造\([x,(n-x)/2,(n-x)/2,\cdots]\),其中\(x\)和\(n\)同奇偶,显然此时异或值可以......
  • 2012-2013 ACM-ICPC, NEERC, Moscow Subregional Contest题解
    题目链接:2012-2013ACM-ICPC,NEERC,MoscowSubregionalContestC.Cinderella(贪心)思路答案为大于平均值的数的数量代码#include<bits/stdc++.h>usingnamespacestd;usingi64=longlong;intmain(){ios::sync_with_stdio(false);cin.tie(nullptr);......
  • [LeetCode] 2390. Removing Stars From a String
    Youaregivenastring s,whichcontainsstars *.Inoneoperation,youcan:Chooseastarin s.Removetheclosest non-star charactertoits left,aswellasremovethestaritself.Return thestringafter all starshavebeenremoved.Note:Thei......
  • “山大地纬杯”第十二届山东省ICPC大学生程序设计竞赛(正式赛)
    C计算几何,每次延长内部多边形的边与外侧多边形形成新的多边形,求这些多边形的最大面积。C++Code#include"bits/stdc++.h"usingnamespacestd;usingi64=longlong;usingReal=double;usingPoint=complex<Real>;#definexreal#defineyimagconstexprRea......
  • 2018icpc青岛F . Tournament
    题目链接:https://codeforces.com/gym/104270/problem/F题意:有n个武士,编号1~n,要进行k轮比赛,每轮比赛中所有武士都要出现,然后两名武士之间会发生决斗,并且一名武士在一轮比赛中只会与另外一名武士决斗,发生决斗的这两名武士,在其他轮比赛中,将不会再次决斗。问能否构造出来符合题......