CodeChef (PERMUT2)


// http://www.codechef.com/problems/PERMUT2

#include <stdio.h>

int main ()
{
    int n;

    while ( scanf ("%d", &n ) && n ) {
        int a [n];

        for ( int i = 0; i < n; i++ )
            scanf ("%d", &a [i]);

        bool flag = true;

        for ( int i = 0; i < n / 2; i++ ) {
            if ( i + 1 != a[a [i] - 1] ) {
                flag = false;
                break;
            }
        }

        if ( flag )
            printf ("ambiguous\n");
        else
            printf ("not ambiguous\n");
    }

    return 0;
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s