#include<bits/stdc++.h> using namespace std; set<int>getRem(set<int>st1, set<int>st2) { for (auto i : st2) { st1.erase(i); } return st1; } int main() {//原则:所有不与自己连通的点必须和自己连接相同的点。 int T; cin >> T; for (int i = 0; i<T; ++i) { int N, M; cin >> N >> M; map<int, set<int>>work; set<int>data; for (int k = 1; k <= N; ++k) { data.insert(k); } for (int j = 0; j<M; ++j) { int a, b; cin >> a >> b; work[a].insert(b); work[b].insert(a); } bool flag = true; while (data.size()>1) { auto point = work.begin(); set<int>rems = getRem(data, point->second); for (auto rem : rems) { if (work[rem] != point->second) { flag = false; break; } } if (!flag) break; for (auto self : rems) { data.erase(self); work.erase(self); } for (auto rest : data) for (auto rem : rems) work[rest].erase(rem); } if (flag) cout << "YES" << endl; else cout << "NO" << endl; } system("pause"); return 0; }
/*
根本不用 dfs, bfs 直接两个 for 循环就行
注意理解题意
我这个 直接 AC 100%, 没有经过 55% 什么中间过程
*/
import java.util.*;
public class Main {
public static class Node{
public int value;
public ArrayList<Node> nexts;
public boolean pass;
public Node(int value){
this.value = value;
nexts = new ArrayList<>();
pass = false;
}
}
public static void process(Scanner in){
int n = in.nextInt();
int m = in.nextInt();
HashMap<Integer, Node> map = new HashMap<>();
for(int i = 0; i < n; i++){
map.put(i+1, new Node(i+1));
}
for(int i = 0; i < m; i++){
int f = in.nextInt();
int s = in.nextInt();
Node nf = map.get(f);
Node ns = map.get(s);
nf.nexts.add(ns);
ns.nexts.add(nf);
}
Node n1 = map.get(1);
map.remove(1);
List<Node> xl = n1.nexts;
List<Node> nxl = new ArrayList<>();
for (Map.Entry<Integer, Node> entry : map.entrySet()) {
if(!xl.contains(entry.getValue())){
nxl.add(entry.getValue());
}
}
boolean pan = false;
for(Node node : nxl){
for(Node node1: xl){
if(!node.nexts.contains(node1)){
pan = true;
break;
}
}
}
if(pan){
System.out.println("No");
}else{
System.out.println("Yes");
}
}
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
for(int i = 0; i < n; i++){
process(in);
}
}
}