Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include<vector>
- #include<iostream>
- using namespace std;
- bool used[100113];
- bool desu[100113];
- vector<int>gr[100113];
- int pr[100113];
- bool x = false;
- int k;
- int m = 0;
- bool dfs2(int v, int p)
- {
- bool fl = false;
- used[v] = 1; pr[v] = p;
- if (m == 0)
- {
- desu[v] = 1;
- }
- if (v == k)
- {
- m++;
- }
- for (int i = 0; i < gr[v].size(); i++)
- {
- if ((gr[v][i] != p) && (desu[gr[v][i]]))
- {
- return true;
- }
- if ((!used[gr[v][i]]))
- {
- fl=dfs2(gr[v][i], v);
- }
- }
- return fl;
- }
- int main()
- {
- int a, b;
- cin >> a >> b >> k;
- int h1, h2;
- for (int i = 0; i < b; i++)
- {
- cin >> h1 >> h2;
- gr[h1].push_back(h2);
- gr[h2].push_back(h1);
- }
- if (b == 1)
- {
- cout << "NO";
- return 0;
- }
- int z=dfs2(1, 0);
- if (z)
- {
- cout << "YES";
- }
- else
- {
- cout << "NO";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement