Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<vector>
- #include<iostream>
- using namespace std;
- bool used[100113];
- vector<int>gr[100113];
- int pr[100113];
- bool x = false;
- int k;
- bool dfs(int v, int p)
- {
- bool fl = false;
- used[v] = 1; pr[v] = p;
- for (int i = 0; i < gr[v].size(); i++)
- {
- if (v == k)
- {
- return true;
- }
- if ((!used[gr[v][i]]))
- {
- fl = dfs(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);
- }
- bool z1 = dfs(1, 0);
- used[0] = 0;
- bool z2 = dfs(1, 0);
- if (z1 && z2)
- {
- cout << "YES";
- }
- else
- {
- cout << "NO";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement