Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL))
- ll const N=2e6;
- vector<ll>v[N+1];
- vector<ll>v1[N+1];
- bool vis[N+1];
- ll cost[100];
- ll level[N+10];
- ll level1[N+10];
- bool flag,cycle;
- ll sub_tree[N+10];
- ll n,m,a,b;
- void input()
- {
- cin>>n>>m;
- ll a,b;
- for(ll i=0; i<m; i++)
- {
- cin>>a>>b;
- v[a].push_back(b);
- v[b].push_back(a);
- }
- }
- void DFS(ll s)
- {
- vis[s]=true;
- for(auto x:v[s])
- {
- if(!vis[x])
- {
- if(x==b)flag=true;
- vis[x]=true;
- DFS(x);
- }
- }
- }
- int main()
- {
- fastread();
- input();
- //ll a,b;
- cin>>a>>b;
- DFS(a);
- if(flag)cout<<"YES"<<endl;
- else cout<<"NO"<<endl;
- }
- /*
- 6 6
- 1 2
- 1 3
- 2 4
- 2 6
- 3 5
- 3 4
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement