首页
比赛
题库
课程
竞赛讨论区
登录
/
注册
去牛客
首页
>
DongDong认亲戚
14条解析
开通博客写题解
sunny_forever
发表于 2021-08-05 20:03:34
并查集 + map Code #include <bits/stdc++.h> using namespace std; const int N = 20010; unordered_map<string,string>fa; int n,m; string find
展开全文
龙文浩2100130836
发表于 2022-07-13 20:46:15
代码1,利用字符串哈希,用map存下来 #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #incl
展开全文
在刷题的单身狗很开心
发表于 2023-09-15 17:21:55
//并查集的模板题,写个并查集完事 #include <bits/stdc++.h> using namespace std; map<string , string> mp; string fin
展开全文
CH_cycyc
发表于 2025-01-09 07:57:25
链接:https://ac.nowcoder.com/acm/contest/22904/1021 来源:牛客网 题目描述 DongDong每年过春节都要回到老家探亲,然而DongDong记性并不好,没法想起谁是谁的亲戚(定义:若A和B是亲戚,B和C是亲戚
展开全文
zhangjitong
发表于 2024-10-06 19:18:36
并查集AC代码+注释如下: #include<bits/stdc++.h> using namespace std; int p[20005]; int get(int x){return p[x]==x?x:p[x]=get(p[x]);}//查询 void merge(int x,i
展开全文
装糊涂高手_
发表于 2022-04-05 23:13:19
并查集模板题 #include <bits/stdc++.h> using namespace std; int fa[20020]; map<string,int> m1; int n,m; int find(int x){ return fa[x] == x ?
展开全文
UtroYAKQ
发表于 2024-05-08 23:18:14
map+并查集 #include<bits/stdc++.h> using namespace std; map<string,string>mp; string find(string x){ return mp[x]==x?mp[x]:mp[x]=find(mp
展开全文
全村最菜的雨林林
发表于 2021-01-27 17:06:34
链接:https://ac.nowcoder.com/acm/problem/23803来源:牛客网 题目描述DongDong每年过春节都要回到老家探亲,然而DongDong记性并不好,没法想起谁是谁的亲戚(定义:若A和B是亲戚,B和C是亲戚,那么A和C也是亲戚),她只好求助于会编程的你了。 输入描
展开全文
hzfan_club
发表于 2022-08-10 10:33:38
并查集板子题,利用map容器储存字符串,注意路径压缩 代码如下: #include<bits/stdc++.h> using namespace std; const int mod=1e9+7; typedef pair<int,int> PII; map<strin
展开全文
Z_L_G
发表于 2025-03-31 19:57:42
题意 n个人,m次操作 每次操作要么在a,b之间建立亲戚关系,要么查询a,b之间是否为亲戚 思路 并查集典例,最开始每个结点的父亲是自己,建立,就合并两个,查询就查询 AC代码 #include<bits/stdc++.h> using namespace std; int f
展开全文
查看本题
查看本题讨论
相关比赛
904-牛客练习赛47
进入比赛
22904-2021秋季算法入门班第五章习题:优先队列、并查集
进入比赛
27245-第三周训练(一)
进入比赛
27450-巩固题单
进入比赛
27604-优先队列、并查集
进入比赛
等你来战
查看全部
第五届上海理工大学程序设计全国挑战赛
报名截止时间:2025-06-28 17:30
牛客周赛 Round 98
报名截止时间:2025-06-29 21:00
牛客小白月赛119
报名截止时间:2025-07-04 21:00
牛客周赛 Round 99
报名截止时间:2025-07-06 21:00
牛客练习赛142
报名截止时间:2025-07-11 21:30
牛客周赛 Round 100
报名截止时间:2025-07-13 21:00
2025牛客暑期多校训练营1
报名截止时间:2025-07-15 17:00
2025牛客暑期多校训练营2
报名截止时间:2025-07-17 17:00
扫描二维码,关注牛客
意见反馈
下载牛客APP,随时随地刷题