/+ dub.sdl:
    name "F"
    dependency "dcomp" version=">=0.6.0"
+/

import std.stdio, std.algorithm, std.range, std.conv;
// import dcomp.foundation, dcomp.scanner;

int main() {
    auto sc = new Scanner(stdin);
    int n; int[] a, b;
    sc.read(n, a, b);
    int[][] ga = new int[][](n);
    int[][] gb = new int[][](n);
    int ra, rb;
    foreach (i; 0..n) {
        if (a[i] != -1) {
            a[i]--;
            ga[a[i]] ~= i;
        } else {
            ra = i;
        }
        if (b[i] != -1) {
            b[i]--;
            gb[b[i]] ~= i;
        } else {
            rb = i;
        }
    }

    int[][] g = new int[][](n);
    bool[] zr = new bool[](n);
    int[][] tr;
    int dfs(int p) {
        int m = tr[p].length.to!int;
        if (m % 2) {
            zr[p] = true;
        }
        int[] v = new int[m];
        foreach (i; 0..m) {
            v[i] = dfs(tr[p][i]);
        }
        foreach (i; 0..m/2) {
            int x = v[2*i], y = v[2*i+1];
            g[x] ~= y; g[y] ~= x;
        }
        if (m % 2 == 0) {
            return p;
        }
        return v[$-1];
    }
    int xx, yy;
    tr = ga; xx = dfs(ra);
    tr = gb; yy = dfs(rb);

    debug writeln(zr);
    debug writeln(g.map!(v => v.length).array);

    if (zr[xx] || zr[yy]) {
        writeln("IMPOSSIBLE");
        return 0; 
        
    }
    foreach (i; 0..n) {
        if (zr[i] && g[i].length) {
            writeln("IMPOSSIBLE");
            return 0; 
        }
    }

    int[] col = new int[](n);
    void mark(int p, int c) {
        col[p] = c;
        foreach (d; g[p]) {
            if (col[d]) continue;
            mark(d, -c);
        }
    }
    foreach (i; 0..n) {
        if (col[i]) continue;
        if (zr[i]) continue;
        mark(i, 1);
    }
    writeln("POSSIBLE");
    writeln(col.map!(to!string).join(" "));

    return 0;
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/foundation.d */
// module dcomp.foundation;
 
static if (__VERSION__ <= 2070) {
    template fold(fun...) if (fun.length >= 1) {
        auto fold(R, S...)(R r, S seed) {
            import std.algorithm : reduce;
            static if (S.length < 2) {
                return reduce!fun(seed, r);
            } else {
                import std.typecons : tuple;
                return reduce!fun(tuple(seed), r);
            }
        }
    }
     
}
version (X86) static if (__VERSION__ < 2071) {
    import core.bitop : bsf, bsr, popcnt;
    int bsf(ulong v) {
        foreach (i; 0..64) {
            if (v & (1UL << i)) return i;
        }
        return -1;
    }
    int bsr(ulong v) {
        foreach_reverse (i; 0..64) {
            if (v & (1UL << i)) return i;
        }
        return -1;   
    }
    int popcnt(ulong v) {
        int c = 0;
        foreach (i; 0..64) {
            if (v & (1UL << i)) c++;
        }
        return c;
    }
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;

 
class Scanner {
    import std.stdio : File;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeChar, isStaticArray, isArray; 
    import std.algorithm : map;
    File f;
    this(File f) {
        this.f = f;
    }
    char[512] lineBuf;
    char[] line;
    private bool succ() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (true) {
            while (!line.empty && line.front.isWhite) {
                line.popFront;
            }
            if (!line.empty) break;
            if (f.eof) return false;
            line = lineBuf[];
            f.readln(line);
        }
        return true;
    }

    private bool readSingle(T)(ref T x) {
        import std.algorithm : findSplitBefore;
        import std.string : strip;
        import std.conv : parse;
        if (!succ()) return false;
        static if (isArray!T) {
            alias E = ElementType!T;
            static if (isSomeChar!E) {
                 
                 
                auto r = line.findSplitBefore(" ");
                x = r[0].strip.dup;
                line = r[1];
            } else {
                auto buf = line.split.map!(to!E).array;
                static if (isStaticArray!T) {
                     
                    assert(buf.length == T.length);
                }
                x = buf;
                line.length = 0;
            }
        } else {
            x = line.parse!T;
        }
        return true;
    }
    int read(T, Args...)(ref T x, auto ref Args args) {
        if (!readSingle(x)) return 0;
        static if (args.length == 0) {
            return 1;
        } else {
            return 1 + read(args);
        }
    }
}


 
 

 


Measured memory_bytes: 27324