SHARE
TWEET

Melysegi bejaras

a guest Oct 15th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. void be(int szl[50][50], int& n) {
  7.     ifstream fin("be.txt");
  8.  
  9.     fin >> n;
  10.  
  11.     for (int i = 1; i < n; i++) {
  12.         fin >> szl[i][0];
  13.  
  14.         for (int j = 1; j <= szl[i][0]; j++)
  15.             fin >> szl[i][j];
  16.     }
  17. }
  18.  
  19. void melysegi(int szl[50][50], int n, int kp) {
  20.     int e = 0, u = 1, ok = 0;
  21.     int freq[50] = {0}, verem[50], ut[50];
  22.    
  23.     //kezdoertekek
  24.     ut[0] = kp;
  25.     freq[kp]++;
  26.     verem[0] = kp;
  27.  
  28.     int csp;
  29.     while (e >= 0) {
  30.         csp = verem[e];
  31.         ok = 0;
  32.  
  33.         for (int i = 1; i <= szl[csp][0] && ok == 0; i++) {
  34.             if (freq[szl[csp][i]] == 0) {
  35.                 ok = 1;
  36.                 verem[++e] = szl[csp][i];
  37.                 ut[u++] = szl[csp][i];
  38.                 freq[szl[csp][i]]++;
  39.             }
  40.         }
  41.        
  42.         if (ok == 0) e--;
  43.     }
  44.  
  45.     //kiiratas
  46.     for (int i = 0; i < u; i++)
  47.         cout << ut[i] <<' ';
  48. }
  49.  
  50. int main()
  51. {
  52.     int szl[50][50], n;
  53.     be(szl, n);
  54.     melysegi(szl, n, 1);
  55. }
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