Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Tested by zydhanlinnar11 on May 31, 2022
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <set>
- #include <cassert>
- using namespace std;
- typedef vector<int> vi;
- typedef vector<vi> vvi;
- typedef set<int> si;
- typedef vector<si> vsi;
- bool dfs(vi &clr, vsi &adjList, int n, int u, int depth) {
- if(clr[u] >= 1) return depth == n;
- clr[u] = 1;
- bool res = false;
- for(auto &v: adjList[u]) res |= dfs(clr, adjList, n, v, depth + 1);
- clr[u] = 0;
- return res;
- }
- int main() {
- #ifdef ZYD_WSL
- freopen("/home/zydhanlinnar11/prakfinal-qa/in", "r", stdin);
- #endif
- int n, m; cin>>n>>m;
- assert(0 <= n && n <= 10);
- assert(0 <= m && m <= 45);
- vvi adjList(n); vsi adjList2(n);
- for(int i=0; i<m; i++) {
- int u, v; cin>>u>>v;
- assert(0 <= u && u < n);
- assert(0 <= v && v < n);
- adjList[u].push_back(v);
- adjList[v].push_back(u);
- }
- for(int i=0; i<n; i++)
- for(auto &j: adjList[i])
- for(auto &v: adjList[j]) {
- if(v == i) continue;
- adjList2[i].insert(v); adjList2[v].insert(i);
- }
- bool ans = false;
- for(int i=0; i<n; i++) {
- vi clr(n, 0);
- ans |= dfs(clr, adjList2, n, i, 0);
- }
- cout<<(ans ? "YES" : "NO")<<"\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement