fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int a=1, i, arr[100005], arrInv[100005], not_amb;
  6. while(a!=0) {
  7. cin>>a;
  8. not_amb=0;
  9. for(i=1; i<=a; i++) {
  10. cin>>arr[i];
  11. }
  12. for(i=1; i<=a; i++) {
  13. arrInv[arr[i]]=i;
  14. }
  15. for(i=1; i<=a; i++) {
  16. if(arr[i]!=arrInv[i]) not_amb=1;
  17. }
  18. if(a!=0) {
  19. if(not_amb) cout<<"not ambiguous"<<endl;
  20. else cout<<"ambiguous"<<endl;
  21. }
  22. }
  23. return 0;
  24. }
Success #stdin #stdout 0s 4000KB
stdin
4
1 4 3 2
5
2 3 4 5 1
1
1
7
6 3 7 2 1 4 5
5
4 1 3 2 5
5
1 3 5 4 2
5
2 5 3 1 4
5
2 5 1 3 4
0
stdout
ambiguous
not ambiguous
ambiguous
not ambiguous
not ambiguous
not ambiguous
not ambiguous
not ambiguous