首页 > DongDong认亲戚
头像 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 展开全文

等你来战

查看全部