ambiguous permutation

#include<stdio.h>
//#include<stdbool.h>
int main(){

int test,j;
int i;
int flag=0;
scanf("%d",&test);
int arr[100000],arr1[100000];
while(test!=0)
{

if(test==0)
break;

   else
   {
     for(i=1;i<=test;i++)
     scanf("%d",&arr[i]);
    
     for(i=1;i<=test;i++)
     {
         j=arr[i];
         arr1[j]=i;    
     }
    
     for(i=1;i<=test;i++)
  
     {
     if(arr[i]!=arr1[i])
       {
         flag=1;
        
       }  
     }      
     if(flag==0) printf("AMBIGUOUS\n");      
     else printf("NOT AMBIGUOUS\n");     
}
 scanf("%d",&test);
}	
return 0;

}

Check it this link -

 http://www.codechef.com/viewsolution/4504231 

and your code after edit -

 http://ideone.com/lKbW66 

flag should be assign zero in while loop .

//