首页 > 其他分享 >P1763 friendly group

P1763 friendly group

时间:2023-05-23 15:12:58浏览次数:32  
标签:group cout P1763 cin friendly int ans const find

/*
 * @Description: To iterate is human, to recurse divine.
 * @Autor: Recursion
 * @Date: 2022-05-16 22:59:39
 * @LastEditTime: 2022-05-16 23:27:17
 */
#include <bits/stdc++.h>
#define LL long long 
using namespace std;
const int maxn = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 1e9 + 10;
const int N = 1e6;
int T,n,m,ans;
int f[N];
int a[N];
int b[N];
 
int find(int x){
    if(f[x] == x)
        return x;
    return f[x] = find(f[x]);
}
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> T;
    int num = 0;
    while(T--){
        ans = 0;
        num ++;
        cin >> n >> m;
        for(int i = 1;i <= n;i ++){
            f[i] = i;
            a[i] = 0;//边
            b[i] = 1;//点
        }
        while(m -- ){
            int x,y;
            cin >> x >> y;
            int u = find(x);
            int v = find(y);
            if(u == v){
                a[v]++;
            }
            else{
                f[u] = v;
                a[v] += a[u] + 1;
                b[v] += b[u];
            }
        }
        for(int i = 1;i <= n;i ++){
                if(i == f[i]&&(a[i] - b[i] >= 0)){
                    ans += a[i] - b[i];
                }
            }
        cout << "Case #" << num << ": " << ans << endl;
    }
 
 
    return 0;
}

 

标签:group,cout,P1763,cin,friendly,int,ans,const,find
From: https://www.cnblogs.com/lhf123/p/17425243.html

相关文章

  • DataFrameGroupBy.agg详解
    DataFrameGroupBy.agg(arg, *args, **kwargs)[source]Aggregateusingcallable,string,dict,orlistofstring/callablesParameters:funcFunctiontouseforaggregatingthedata.Ifafunction,musteitherworkwhenpassedaDataFrameorwhenpassedto......
  • Jmeter函数助手13-threadGroupName
    threadGroupName函数获取当前线程组的名称。该函数没有参数,直接引用即可。1、返回当前线程组的名称......
  • Java8 Stream --groupingBy 分组讲解
    本文主要讲解:Java8Stream之Collectors.groupingBy()分组示例Collectors.groupingBy()分组之常见用法功能代码:/***使用java8streamgroupingBy操作,按城市分组list*/publicvoidgroupingByCity(){Map<String,List<Employee>>map=employe......
  • ShardingSphere + Pagehelper 组合sql查询中包含 DISTINCT GROUP BY 等关键字和聚合函
    Pagehelper中配置说明params:为了支持startPage(Objectparams)方法,增加了该参数来配置参数映射,用于从对象中根据属性名取值,可以配置 pageNum,pageSize,count,pageSizeZero,reasonable,不配置映射的用默认值,默认值为pageNum=pageNum;pageSize=pageSize;count=countSql;r......
  • Pandas GroupBy 使用教程
    实例1将分组后的字符拼接importpandasaspddf=pd.DataFrame({'user_id':[1,2,1,3,3],'content_id':[1,1,2,2,2],'tag':['cool','nice','clever','clever','not-bad']})df将d......
  • MySQL之only_full_group_by
    https://www.cnblogs.com/JaxYoun/p/13177993.htmlMySQL之only_full_group_by 开发环境连接的mysql5.6,而测试环境是mysql5.7。开发中有小伙伴写了有关groupby的sql语句。在开发环境中运行是正常的,而到了测试环境中就发现了异常。原因分析:MySQL5.7版本默认设置了mysqlsql......
  • mysql 5.7 Expression #1 of ORDER BY clause is not in GROUP BY clause and contain
    https://www.shuzhiduo.com/A/gGdX3BNp54/https://blog.csdn.net/wufaqidong1/article/details/126263023 使用mysql在执行一条插入语句时insertintochannel(channel_id,channel_no,channel_name)values(1,'',"hhh");报错:Expression#1ofORDERBYclaus......
  • AntDeisgn中checkbox group的使用
    <template><!--弹窗类型选择--><div><a-modal:visible="state.modalAttr.visible"title="规选类型"width="680px"@ok="showModal"@cancel="hideModal"><a-checkbox......
  • Bela Ban's JGroups Manual Translation Serial IV - 协议栈和高级概念
    本章讨论怎么样正确使用和配置JGroups的协议栈协议,以及一些 JGroups 的高级概念。1.jGroups协议栈   我们知道jGroups是一个可靠多播传输工具包,它能够为集群中成员提供点对点,点对组的通信,所有通信通过通道完成。通道基于协议栈之上,协议栈中协议各自有自己特别的功能,这些功能......
  • 如何保证group by 留下的数据是想要的那一条
    比如我想要groupby结果为日期最大的一条使用子查询,先将数据使用orderby按日期字段排序,再在外层使用groupby分组。留下的数据是:如groupbya那留下的是orderbya后的第一条;所以如果想要留下一定的数据,请先嵌套一层查询,如select*from(select*fromtable_a......