京东笔试第一题 多部图
//京东笔试第一题 多部图
//蒟蒻做了一个小时。代码写的很烂。。。大神请忽略。
#include<iostream>
#include<set>
#include<vector>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n, m;
cin>>n>>m;
set<int> a[n + 1];
int x, y;
for(int i = 0; i < m; ++i){
cin>>x>>y;
a[x].insert(y);
a[y].insert(x);
}
for(int i = 1; i <= n; ++i){
if(a[i].size() == n){
continue;
}
else if(a[i].size() == n - 1){
a[i].insert(i);
}
else{
vector<int> increase;
increase.push_back(i);
for(int j = i + 1; j <= n; ++j){
if(a[i] == a[j]){
increase.push_back(j);
}
}
for(int j = i + 1; j <= n; ++j){
if(a[i] == a[j]){
for(int k = 0; k < increase.size(); ++k){
a[j].insert(increase[k]);
}
}
}
for(int k = 0; k < increase.size(); ++k){
a[i].insert(increase[k]);
}
}
}
int falg = 0;
for(int i = 1; i <= n; ++i){
if(a[i].size() == n){
continue;
}
else{
falg++;
}
}
if(falg == 0)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
return 0;
}
#京东##笔试题目##include<set>
#include<vector>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n, m;
cin>>n>>m;
set<int> a[n + 1];
int x, y;
for(int i = 0; i < m; ++i){
cin>>x>>y;
a[x].insert(y);
a[y].insert(x);
}
for(int i = 1; i <= n; ++i){
if(a[i].size() == n){
continue;
}
else if(a[i].size() == n - 1){
a[i].insert(i);
}
else{
vector<int> increase;
increase.push_back(i);
for(int j = i + 1; j <= n; ++j){
if(a[i] == a[j]){
increase.push_back(j);
}
}
for(int j = i + 1; j <= n; ++j){
if(a[i] == a[j]){
for(int k = 0; k < increase.size(); ++k){
a[j].insert(increase[k]);
}
}
}
for(int k = 0; k < increase.size(); ++k){
a[i].insert(increase[k]);
}
}
}
int falg = 0;
for(int i = 1; i <= n; ++i){
if(a[i].size() == n){
continue;
}
else{
falg++;
}
}
if(falg == 0)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
return 0;
}