RE求助
  • 板块P1551 亲戚
  • 楼主thlog5
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/7/19 11:33
  • 上次更新2024/7/19 13:13:21
查看原帖
RE求助
916028
thlog5楼主2024/7/19 11:33
#include<bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
#define re register
#define ri register int

#define For(i,t,n) for(ri i = t; i <= n; i++)
#define dFor(i,t,n) for(ri i = t; i >= n; i--)

#define syncoff ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
//#define int LL

const int Inf = 0x3f3f3f3f;
const int memInf = 0x3f;

inline int read() {
    ri x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = (x<<3)+(x<<1) + (ch^48);
        ch = getchar();
    }
    return x * f;
}
inline void read(int &x) {
    x = 0; ri f = 1, ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = (x<<3)+(x<<1) + (ch^48);
        ch = getchar();
    }
    x*=f;
}

int n,m,p;

struct uset{
	int fa[5005];
//      int init(int n=5000){
//		For(i,0,n) fa[i]=i;
//	}
	int get(int x){
		if(fa[x]==x) return x;
		return fa[x]=get(fa[x]);
	}
	inline bool same(const int& x,const int& y){
		return (get(x)==get(y));
	}
	void merge(const int& x,const int& y){
		ri a=get(x),b=get(y);
		fa[b]=a;
	}
	
	uset(int n=5000){
                //init();
		For(i,0,n) fa[i]=i;
	}
};
uset u;
void input(){
	read(n); read(m); read(p);
	For(i,1,m){
		ri a=read(),b=read();
		u.merge(a,b);
	}
}
void solve(){
	input();
	while(p--){
		ri a=read(),b=read();
		if(u.same(a,b)) printf("Yes\n");
		else printf("No\n");
	}
}

signed main()
{
    solve();
    return 0;
}


如果使用注释掉的 init()init() 函数进行初始化就会 RE ,求大佬解答。

2024/7/19 11:33
加载中...