Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <stdio.h>
- #include <vector>
- #include <queue>
- using namespace std;
- void smista(int N, int nemico[]) {
- freopen ("input.txt","r",stdin);
- freopen ("output.txt","w",stdout);
- int aQualeGruppo[N];
- bool can[N];
- for(int i = 0; i < N; i++)
- {
- aQualeGruppo[i] = -1; // la persona i appartiene al gruppo 0, 1, 2..
- can[N] = true;
- }
- int lastGroup = 0;
- int i;
- bool canCont = true;
- bool firstTime;
- while(canCont) {
- canCont = false;
- firstTime = true;
- for (i = 0; i < N; i++) {
- // cout << " ------- " << endl;
- // cout << aQualeGruppo[i] << ", " << aQualeGruppo[nemico[i]] << ", " << (can[i] ? "si" : "no") << endl;
- //cout << " f ---- f" << endl;
- if(aQualeGruppo[i] == -1 && aQualeGruppo[nemico[i]] != lastGroup && can[i])
- {
- if(nemico[i] > i)
- can[nemico[i]] = false;
- aQualeGruppo[i] = lastGroup;
- if(!firstTime)
- cout << " ";
- cout << i;
- firstTime = false;
- }
- can[i] = true;
- if(aQualeGruppo[i] == -1)
- canCont = true;
- }
- lastGroup++;
- if(canCont)
- cout << endl;
- }
- }
- int main1()
- {
- freopen ("input.txt","r",stdin);
- freopen ("output.txt","w",stdout);
- int n;
- cin >> n;
- int nemico[n];
- for(int i = 0; i < n; i++)
- cin >> nemico[i];
- smista(n, nemico);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement