• CodeForce VKcup A


    题目描述:例如A-B,B-C是好朋友,那么A-C一定是好朋友,给一些点,和一些描述,观察是否成立

    题目链接:点我

    一个互相认识的团体,一定是每个点都和其他点相连的,那么边数为n(n-1)/2,把得到的每个团体边数相加,如果不等于总边数,那么就某些团体没有全连接,就不符号

    求每个团体的人数用并查集或者搜索,并查集写起来简单点

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<cstring>
     4 const int MAXN=150005;//点数
     5 const int MAXM=100005;//边数
     6 #define cl(a) memset(a,0,sizeof(a))
     7 #define ts printf("*****
    ");
     8 int f[MAXN],sum[MAXN];
     9 int find(int x)
    10 {
    11     if(f[x]==-1)return x;
    12     return f[x]=find(f[x]);
    13 }
    14 void bing(int u,int v)
    15 {
    16     int t1=find(u),t2=find(v);
    17     if(t1!=t2){
    18         f[t1]=t2;
    19         sum[t2]+=sum[t1];
    20     }
    21 }
    22 int main()
    23 {
    24     int n,m;
    25     int i,j,v;
    26     while(scanf("%d%d",&n,&m)!=EOF)
    27     {
    28         memset(f,-1,sizeof(f));
    29         int q,p;
    30         int u,v;
    31         for(i=0;i<=n;i++)   sum[i]=1;
    32         for(i=1;i<=m;i++)
    33         {
    34             scanf("%d%d",&u,&v);
    35             bing(u,v);
    36         }
    37         long long cnt=0;
    38         for(i=1;i<=n;i++){
    39             if(find(i)==i){
    40                 cnt+=(long long)(sum[i]-1)*sum[i]/2;
    41             }
    42         }
    43         if(cnt==(long long)m){
    44             printf("YES
    ");
    45         }
    46         else printf("NO
    ");
    47     }
    48     return 0;
    49 }
  • 相关阅读:
    优化总结文章链接
    帧同步、状态同步
    ecs
    AStarPathFinding
    unity 热更方案对比
    C#数据类型
    JavaScript基础
    CSS中margin和padding的区别
    css选择器
    hadoop中使用shell判断HDFS文件是否存在
  • 原文地址:https://www.cnblogs.com/cnblogs321114287/p/6581196.html
Copyright © 2020-2023  润新知