当前位置:网站首页>HDU Ice_ Cream's world I
HDU Ice_ Cream's world I
2022-04-22 07:30:00 【S atur】
The question : Give a n A little bit m A multiplicity free graph with edges , Try to find out the maximum number of non overlapping rings .

Ideas : Just deform the merge function of the joint search set ~ There is no need to consider whether to take a large ring or a small ring , As long as the newly added edge can form a closed loop , It must be adding a separate ring or dividing an original ring into two , Contributions are 1.
#include<bits/stdc++.h>
#define endl '\n'
#define null NULL
#define ll long long
#define int long long
#define pii pair<int, int>
#define lowbit(x) (x &(-x))
#define ls(x) x<<1
#define rs(x) (x<<1+1)
#define me(ar) memset(ar, 0, sizeof ar)
#define mem(ar,num) memset(ar, num, sizeof ar)
#define rp(i, n) for(int i = 0, i < n; i ++)
#define rep(i, a, n) for(int i = a; i <= n; i ++)
#define pre(i, n, a) for(int i = n; i >= a; i --)
#define IOS ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int way[4][2] = {
{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
using namespace std;
const int inf = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-6;
const ll mod = 1e9+7;
const int N = 2e5 + 5;
inline void read(int &x){
char t=getchar();
while(!isdigit(t)) t=getchar();
for(x=t^48,t=getchar();isdigit(t);t=getchar()) x=x*10+(t^48);
}
int n, m, f[N], ans;
int find(int x)
{
return x == f[x]?x:f[x] = find(f[x]);
}
int join(int x, int y)
{
int a = find(x), b = find(y);
if(a != b){
f[a] = b;
return 0;
}
return 1; // If the root node is the same , Can form a ring
}
signed main()
{
IOS;
cin >> n >> m;
for(int i = 0; i < n; i ++) f[i] = i;
while(m --){
int u, v; cin >> u >> v;
ans += join(u, v);
}
cout << ans << endl;
return 0;
}
版权声明
本文为[S atur]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220616060531.html
边栏推荐
- 1. Jam packed (Game 5 of 2021 training League warm-up training competition)
- Links summary qwq
- Educational Codeforces Round 125 (Rated for Div. 2)
- L2-005 集合相似度(set判重)
- 八大排序的思想及其代码
- Codeforces Round #634 (Div. 3)
- A. Binary seating (the fifth game of 2021 training League warm-up training competition)
- In the process of class loading, the allocation area of class variables is different from that of instance variables
- 带环链表详解
- 843 · 数字翻转
猜你喜欢

HDU Ice_cream‘s world I (并查集判环)

363 · 接雨水

接口的讲解以及使用

Leetcode - 4 - (longest substring without repeated characters, candy distribution, binary tree traversal)

(5) Use Navicat to create database data table and set ID auto increment

L2-005 set similarity (set judgment)

B. Cutting corners (simple geometry / sign in) (Game 5 of 2021 Training Alliance warm-up training competition)

Vivado generates and invokes EDF netlist files

A.Binary Seating (概率) (2021年度训练联盟热身训练赛第五场)

Cannot find interface mapping after updating HDF
随机推荐
Unknown graphics extension:. 1 jpg. }
843 · 数字翻转
指针 结构体 const 小结
Codeforces Round #623
Points for attention in Modelsim simulation acceleration
If I make this silly mistake again/ (ㄒoㄒ)/~~
Singleton pool, singleton bean, singleton mode
Codeforces Round #776 (Div. 3)
Introduction
LeetCode - 6 - (字符串相乘、下一个更大元素<ⅠⅡⅢ>、k个一组翻转链表)
Vivado generates and invokes EDF netlist files
重写与重载的定义与区别
A. Alice and Bob (game? Thinking & Violence) (2021 Niuke summer multi school training camp 1)
Redis Advanced
C. Ducky debugging (Game 5 of 2021 training League warm-up training competition)
Leetcode - 7 - (nearest common ancestor of binary tree, rotation array, direct of binary tree, next permutation, combined sum)
2021学习计划
F. Find 3-friendly Integers (特殊数字 / 找规律) (2021牛客暑期多校训练营1)
八大排序的思想及其代码
L2-004 这是二叉搜索树吗?(先序输入&判断搜索二叉树&后序输出)