https://www.luogu.com.cn/problem/CF25D
目录
前言
- 前言
- 思路
- CODE
乱做的 做的时候还怀疑能不能满足 但是就是过了样例
思路一开始 以为是图论 这是需要dfs遍历吗? 怎么判断集合呢
一说到集合 就 搞到了 并查集
然后就没有然后了 代码很简单
CODE#include
using namespace std;
typedef long long ll;
const int N = 1e3+10;
int p[N],n;
struct node
{
int to,ed;
} num[N];
int idx;
struct nd
{
int x,y;
int to,ed;
} add[N];
int id ;
int find(int x)
{
if(x!=p[x])
return p[x] =find(p[x]);
return p[x];
}
void solve()
{
cin>>n;
for(int i =1; ia>>b;
int fa= find(a);
int fb= find(b);
if(fa == fb)
{
num[++idx].to = a;
num[idx].ed = b;
//cout
关注
打赏