您当前的位置: 首页 > 

*DDL_GzmBlog

暂无认证

  • 3浏览

    0关注

    605博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

[Luogu] CF25D Roads not only in Berland

*DDL_GzmBlog 发布时间:2021-06-23 18:04:28 ,浏览量:3

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            
关注
打赏
1657615554
查看更多评论
0.0387s