1 条题解

  • 1
    @ 2021-10-16 15:59:27
    /*****************************************
    备注:
    ******************************************/
    #include <queue>
    #include <math.h>
    #include <stack>
    #include <stdio.h>
    #include <iostream>
    #include <vector>
    #include <iomanip>
    #include <string.h>
    #include <algorithm>
    using namespace std;
    #define LL long long
    const int N = 2e5 + 10;
    const int INF = 0x3f3f3f3f;
    int a[N];
    void init(int n)
    {
    	for(int i = 0 ; i <= n ; i++)
    		a[i] = i;
    }
    int fa(int x)
    {
    	if(x == a[x])
    		return x;
    	return a[x] = fa(a[x]);
    }
    inline int read()
    {
    	char ch = getchar();
    	while(ch > '9' || ch < '0')
    		ch = getchar();
    	int sum = 0;
    	while(ch <= '9' && ch >= '0')
    	{
    		sum = (sum << 3) + (sum << 1) + ch - '0';
    		ch = getchar();
    	}
    	return sum;
    }
    int main()
    {
    	int n , m;
    
    	n = read() , m = read();
    	init(n);
    	while(m--)
    	{
    		int x,y;
    		x = read() , y =read();
    		x = fa(x) , y= fa(y);
    		a[x] = y;
    	}
    	int t;
    	t = read();
    	while(t--)
    	{
    		int x, y;
    		x = read(); y = read();
    		x = fa(x);
    		y = fa(y);
    		if(x != y)	cout << "No\n";
    		else cout << "Yes\n";
    	}
    	return 0;
    }
    
    • 1

    信息

    ID
    1314
    时间
    1000ms
    内存
    256MiB
    难度
    6
    标签
    递交数
    140
    已通过
    38
    上传者