Advertisement
meriellez

Untitled

May 22nd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int a[101][101],k=1;
  4. int n;
  5. bool t[101];
  6. void dfs(int s){
  7. int r;
  8. t[s]=true;
  9. for(r=0;r<n;r++){
  10. if(a[s][r]==1 && t[r]==false){
  11. dfs(r);
  12. k++;
  13. }
  14. }
  15. }
  16. int main (){
  17. int i,j,s;
  18. cin >>n >>s;
  19. for(i=0;i<n;i++){
  20. t[i]=false;
  21. for(j=0;j<n;j++){
  22. cin >>a[i][j];
  23. }
  24. }
  25. dfs(s-1);
  26. cout <<k;
  27. return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement