Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _GLIBCXX_DEBUG
- #include <iostream>
- #include <vector>
- using namespace std;
- int v, e;
- vector<vector<int>> g(v + 10);
- vector<bool> col(v + 10, 0);
- int countt = 0;
- void dfs(int u){
- if (col[u]){
- return;
- }
- col[u] = 1;
- countt++;
- for(int i = 0; i < g[u].size(); i++){
- dfs(g[u][i]);
- }
- }
- int main(){
- cin >> v >> e;
- if (e != v - 1){
- cout << "NO" << '\n';
- return 0;
- }
- for(int i = 0; i < e; i++){
- int a, b;
- cin >> a >> b;
- a--;
- b--;
- g[a].push_back(b);
- g[b].push_back(a);
- }
- dfs(0);
- if (countt == v){
- cout << "YES" << '\n';
- }
- else{
- cout << "NO" << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement