Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int ile;
- cin >> ile;
- for(int i = 0; i < ile; i++){
- int n;
- cin >> n;
- int last = n;
- int ilosc_wystapien[n] = {};
- int dokad_teleportacja[n] = {};
- for(int j = 0; j < n; j++){
- int temp;
- cin >> temp;
- dokad_teleportacja[j] = temp;
- ilosc_wystapien[temp-1]++;
- }
- while(1){
- int wynik = 0;
- for(int j = 0; j < n; j++){
- if(ilosc_wystapien[j] != 0){
- wynik++;
- ilosc_wystapien[j] = 0;
- ilosc_wystapien[dokad_teleportacja[j]-1]++;
- }
- }
- if(wynik == last ){
- break;
- }
- last = wynik;
- }
- cout << last<< endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment