Th3NiKo

Obrazy i pokoje

Apr 6th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int ile;
  8.     cin >> ile;
  9.     for(int i = 0; i < ile; i++){
  10.         int n;
  11.         cin >> n;
  12.         int last = n;
  13.         int ilosc_wystapien[n] = {};
  14.         int dokad_teleportacja[n] = {};
  15.         for(int j = 0; j < n; j++){
  16.             int temp;
  17.             cin >> temp;
  18.             dokad_teleportacja[j] = temp;
  19.             ilosc_wystapien[temp-1]++;
  20.         }
  21.         while(1){
  22.             int wynik = 0;
  23.             for(int j = 0; j < n; j++){
  24.                 if(ilosc_wystapien[j] != 0){
  25.                     wynik++;
  26.                     ilosc_wystapien[j] = 0;
  27.                     ilosc_wystapien[dokad_teleportacja[j]-1]++;
  28.                 }
  29.             }
  30.             if(wynik == last ){
  31.                 break;
  32.             }
  33.             last = wynik;
  34.         }
  35.         cout << last<< endl;
  36.     }
  37.     return 0;
  38. }
Add Comment
Please, Sign In to add comment