层次遍历BFS
并查集判断
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstring>
using namespace std;
const int N = 1e4+5;
const int INF = 0x3f3f3f3f;
int n, m, cntt;
int root[N];
int vis[N];
vector<int> G[N];
int find(int x){
if(root[x] != x) root[x] = find