SHARE
TWEET

Untitled

a guest Nov 14th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <fstream>
  2. using namespace std;
  3. ifstream fin("dfs.in");
  4. ofstream fout("dfs.out");
  5. int n, m, x, k, i, j, a[100][100], viz[101];
  6. void citire(){
  7.     fin >> n >> m >> x;
  8.     for(int k = 1; k <= m; k++){
  9.         fin >> i >> j;
  10.             a[i][j] = a[j][i] = 1;
  11.     }
  12. }
  13. void df(int k){
  14.     viz[k] = 1;
  15.     fout << k <<" ";
  16.     for(int i = 1; i <= n; i++)
  17.         if(a[k][i] == 1 && viz[i] == 0)
  18.             df(i);
  19.        
  20.  
  21.  
  22.  
  23. }
  24. int main()
  25. {
  26.     citire();
  27.     df(x);
  28.     return 0;
  29. }
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