SHARE
TWEET

Get a tree (Ağac düzəlt)

kananasgarli90 Jun 5th, 2020 934 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int e[101][101], color[101], n, m, u, v, say, til;
  4. void dfs(int s){
  5.     color[s] = 1;
  6.     for(int i = 1; i <= n; i++){
  7.         if(e[s][i] == 1 && color[i] == 0){
  8.             cout<<s<<" "<<i<<endl;
  9.             dfs(i);
  10.         }
  11.     }
  12. }
  13. int main()
  14. {
  15.     cin>>n>>m;
  16.     while(m--){
  17.         cin>>u>>v;
  18.         e[u][v] = e[v][u] = 1;
  19.     }
  20.     dfs(1);
  21. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top