Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 100005;
- const int red = 1;
- const int blue = 2;
- vector<int> adj[100005];
- bool color[100005];
- bool vis[100005];
- int par[100005];
- bool oddCycle(int u) {
- if (vis[u] == true) return false;
- queue<int> q;
- q.push(u);
- color[u] = false;
- vis[u] = true;
- while (!q.empty()) {
- int v = q.front();
- q.pop();
- for (int i = 0; i < adj[v].size(); i++) {
- int w = adj[v][i];
- if (!vis[w]) {
- vis[w] = true;
- q.push(w);
- color[w] = !color[v];
- }
- else{
- if(color[w]==color[v]){
- return true;
- }
- }
- }
- }
- return false;
- }
- int main() {
- int n, e;
- scanf("%d %d", &n, &e);
- for (int i = 0; i < n; i++) par[i] = -1;
- for (int i = 0; i < e; i++) {
- int u, v;
- scanf("%d %d", &v, &u);
- adj[u].push_back(v);
- adj[v].push_back(u);
- }
- bool t = false;
- for (int i = 0; i < n; i++) {
- t = oddCycle(i);
- if (t) break;
- }
- if (t)
- printf("Yes\n");
- else
- printf("No\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement