Created
September 4, 2016 07:47
-
-
Save ryzokuken/2c0fcdb350e6a13151e74ca549b6fba9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <algorithm> | |
#include <vector> | |
using namespace std; | |
bool exists(vector <int> a, int val) { | |
if(find(a.begin(), a.end(), val) != a.end()) | |
return true; | |
return false; | |
} | |
bool knowsAll(vector <int> person, vector <int> people) { | |
bool knows = true; | |
for(int i = 0; i < people.size() && knows; i++) | |
if(!exists(person, people[i])) | |
knows = false; | |
return knows; | |
} | |
int main() { | |
int t; | |
cin >> t; | |
for(int i = 0; i < t; i++) { | |
int n, m; | |
cin >> n >> m; | |
vector <int> table1; | |
vector <int> table2; | |
vector <int> graph[n]; | |
for(int j = 0; j < m; j++) { | |
int x, y; | |
cin >> x >> y; | |
graph[x - 1].push_back(y - 1); | |
graph[y - 1].push_back(x - 1); | |
} | |
bool flag = true; | |
for(int j = 0; j < n && flag; j++) { | |
bool k_t1 = knowsAll(graph[j], table1); | |
if(k_t1) { | |
table1.push_back(j); | |
continue; | |
} | |
bool k_t2 = knowsAll(graph[j], table2); | |
if(k_t2) { | |
table2.push_back(j); | |
continue; | |
} | |
flag = false; | |
} | |
if(flag) | |
cout << "YES" << endl; | |
else | |
cout << "NO" << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment