Language: C++

#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>

namespace lib
{
	template<std::uint64_t Mod>struct modnum;
	template<class T>constexpr T pow(T base, std::size_t p)
	{
		if (p == 0)
		{
			return T(1);
		}
		else if (p == 1)
		{
			return base;
		}
		else if (p == 2)
		{
			return base*base;
		}
		else if (p % 2 == 0)
		{
			return pow(pow(base, p / 2), 2);
		}
		else
		{
			return pow(pow(base, p / 2), 2)*base;
		}
	}
	template<std::uint64_t Mod>constexpr auto inverse(modnum<Mod> const&);

	template<std::uint64_t Mod>struct modnum
	{
		static constexpr auto mod = Mod;
		std::uint64_t val;
		modnum() = default;
		constexpr modnum(std::uint64_t v):val(v%Mod)
		{

		}

		constexpr modnum& operator+=(modnum const& v)
		{
			val += v.val;
			val %= mod;
			return *this;
		}
		constexpr modnum& operator-=(modnum const& v)
		{
			val += mod - v.val;
			val %= mod;
			return *this;
		}
		constexpr modnum& operator*=(modnum const& v)
		{
			val *= v.val;
			val %= mod;
			return *this;
		}
		constexpr modnum& operator/=(modnum const& v)
		{
			return operator*=(inverse(v));
		}
	};
	template<std::uint64_t Mod>constexpr auto operator+(modnum<Mod> lhs, modnum<Mod>const& rhs)
	{
		return lhs += rhs;
	}
	template<std::uint64_t Mod>constexpr auto operator-(modnum<Mod> lhs, modnum<Mod>const& rhs)
	{
		return lhs -= rhs;
	}
	template<std::uint64_t Mod>constexpr auto operator*(modnum<Mod> lhs, modnum<Mod>const& rhs)
	{
		return lhs *= rhs;
	}
	template<std::uint64_t Mod>constexpr auto operator/(modnum<Mod> lhs, modnum<Mod>const& rhs)
	{
		return lhs /= rhs;
	}

	template<std::uint64_t Mod>constexpr auto inverse(modnum<Mod>const& base)
	{
		return pow(base, Mod - 2);
	}

	template<class T>constexpr auto clamp(T v)
	{
		return std::max(v, T());
	}
	template<class T>void sort(std::vector<T>& vec)
	{
		std::sort(vec.begin(), vec.end());
	}

	template<class T>auto lower_bound(std::vector<T>const& vec, T v)
	{
		return std::distance(vec.begin(), std::lower_bound(vec.begin(), vec.end(), v));
	}
	template<class T>auto upper_bound(std::vector<T>const& vec, T v)
	{
		return std::distance(vec.begin(), std::upper_bound(vec.begin(), vec.end(), v));
	}

	struct scope_exit
	{
		std::function<void(void)> func;
		scope_exit(std::function<void(void)> f):func(f)
		{

		}
		~scope_exit()
		{
			func();
		}
	};

	template<int val>using int_tag = std::integral_constant<int, val>;

	template<class Return, class Argument>struct minimam_searcher
	{
		Return operator()(std::function<Return(Argument)> func, Argument beg, Argument end)const
		{
			Return min = std::numeric_limits<Return>::max();
			for (; beg != end; ++beg)
			{
				min = std::min(min, func(beg));
			}
			return min;
		}
	};
	template<class Return, class Argument>constexpr minimam_searcher<Return, Argument> minimam{};

	template<class T>T gcd(T a, T b)
	{
		if (a > b)
		{
			return gcd(b, a);
		}
		if (a == T())
		{
			return b;
		}
		return gcd(b%a, a);
	}

	static constexpr int intlog2(int x)
	{
		for (int i = 0, j = 2; i < 32; ++i, j <<= 1)
		{
			if (j > x)
			{
				return i;
			}
		}
		return 32;
	}

	struct segtree
	{
		std::vector<std::int64_t> tree;
		std::size_t depth_;
		segtree(std::size_t depth):tree(std::size_t(1) << (depth + 1)), depth_(depth)
		{

		}

		void change(std::size_t index, std::int64_t val)
		{
			change(index, val, 0);
		}

		std::int64_t get(std::size_t left, std::size_t right)//[left, right]の範囲
		{
			return get(left, right + 1, 0, 1, 0);
		}

		void increment(std::size_t index)
		{
			increment(index, 0);
		}

		void decrement(std::size_t index)
		{
			decrement(index, 0);
		}
	private:
		std::int64_t change(std::size_t index, std::int64_t val, std::size_t dep)
		{
			auto shift = std::size_t(1) << dep;
			auto s = std::size_t(1) << (depth_ - dep);
			if (dep == depth_)
			{
				std::swap(tree[shift + index / s - 1], val);
				return val;
			}
			else
			{
				auto v = change(index, val, dep + 1);
				tree[shift + index / s - 1] += val - v;
				return v;
			}
		}

		std::int64_t get(std::size_t a, std::size_t b, std::size_t left, std::size_t right, std::size_t dep)
		{
			auto lshift = left << (depth_ - dep);
			auto rshift = right << (depth_ - dep);
			if (a <= lshift && rshift <= b)
			{
				return tree[(std::size_t(1) << dep) + left - 1];
			}
			else if (rshift <= a || b <= lshift)
			{
				return 0;
			}
			else
			{
				return
					get(a, b, left << 1, left + right, dep + 1) +
					get(a, b, left + right, right << 1, dep + 1);
			}
		}

		void increment(std::size_t index, std::size_t dep)
		{
			auto shift = std::size_t(1) << dep;
			auto s = std::size_t(1) << (depth_ - dep);
				++tree[shift + index / s - 1];
			if (dep != depth_)
			{
				increment(index, dep + 1);
			}
		}

		void decrement(std::size_t index, std::size_t dep)
		{
			auto shift = std::size_t(1) << dep;
			auto s = std::size_t(1) << (depth_ - dep);
			--tree[shift + index / s - 1];
			if (dep != depth_)
			{
				decrement(index, dep + 1);
			}
		}
	};
}
namespace std
{
	template<std::uint64_t Mod>decltype(auto) operator<<(ostream& ost, lib::modnum<Mod>const& v)
	{
		return ost << v.val;
	}
}

void Main();
int main()
{
	std::cin.tie(nullptr);
	std::cin.sync_with_stdio(false);
	Main();
}

bool check(std::vector<int>& redge, std::vector<std::set<int>>const& imp, int start, int now, int prev)
{
	if (now == start)
	{
		return !imp[now].count(j) && prev == j;
	}
	int j = 0;
	for (; j < 3; ++j)
	{
		if (!imp[now].count(j) && prev != j)
		{
			break;
		}
	}
	return check(redge, imp, start, redge[now], j);
}

void Main()
{
	int N;
	std::cin >> N;
	std::vector<std::pair<int, int>> edge(N);
	std::vector<int> reverse_edge(N);
	for (int i = 0; i < N; ++i)
	{
		int p;
		std::cin >> p;
		--p;
		++edge[p].first;
		edge[p].second = i;
		reverse_edge[i] = p;
	}
	if (std::any_of(edge.begin(), edge.end(), [](auto const& v) {return v.size() == 0; }))
	{
		std::vector<std::set<int>> imp(N);
		int start = 0;
		for (int i = 0; i < N; ++i)
		{
			imp[i].emplace(0);
			if (edge[i].first == 0)
			{
				int j = i;
				do
				{
					j = reverse_edge[j];
					start = j;
					imp[j].emplace(1 - *(imp[edge[j].second].begin()));
				} while (edge[j].first < 2);
			}
		}
		int j = 0;
		for (; j < 3; ++j)
		{
			if (!imp[start].count(j))
			{
				break;
			}
		}
		if (check(reverse_edge, imp, start, reverse_edge[start], j))
		{
			std::cout << "POSSIBLE" << std::endl;
		}
		else
		{
			std::cout << "IMPOSSIBLE" << std::endl;
		}
	}
	else
	{
		if (N % 2 == 0)
		{
			std::cout << "POSSIBLE" << std::endl;
		}
		else
		{
			std::cout << "IMPOSSIBLE" << std::endl;
		}
	}
}

Compiler output:
a.cc:17:18: error: 'std::uint64_t' has not been declared
   17 |         template<std::uint64_t Mod>struct modnum;
      |                  ^~~
a.cc:41:18: error: 'std::uint64_t' has not been declared
   41 |         template<std::uint64_t Mod>constexpr auto inverse(modnum<Mod> const&);
      |                  ^~~
a.cc:41:66: error: 'Mod' was not declared in this scope
   41 |         template<std::uint64_t Mod>constexpr auto inverse(modnum<Mod> const&);
      |                                                                  ^~~
a.cc:41:69: error: template argument 1 is invalid
   41 |         template<std::uint64_t Mod>constexpr auto inverse(modnum<Mod> const&);
      |                                                                     ^
a.cc:43:18: error: 'std::uint64_t' has not been declared
   43 |         template<std::uint64_t Mod>struct modnum
      |                  ^~~
a.cc:76:18: error: 'std::uint64_t' has not been declared
   76 |         template<std::uint64_t Mod>constexpr auto operator+(modnum<Mod> lhs, modnum<Mod>const& rhs)
      |                  ^~~
a.cc:76:68: error: 'Mod' was not declared in this scope
   76 |         template<std::uint64_t Mod>constexpr auto operator+(modnum<Mod> lhs, modnum<Mod>const& rhs)
      |                                                                    ^~~
a.cc:76:71: error: template argument 1 is invalid
   76 |         template<std::uint64_t Mod>constexpr auto operator+(modnum<Mod> lhs, modnum<Mod>const& rhs)
      |                                                                       ^
a.cc:76:85: error: 'Mod' was not declared in this scope
   76 |         template<std::uint64_t Mod>constexpr auto operator+(modnum<Mod> lhs, modnum<Mod>const& rhs)
      |                                                                                     ^~~
a.cc:76:88: error: template argument 1 is invalid
   76 |         template<std::uint64_t Mod>constexpr auto operator+(modnum<Mod> lhs, modnum<Mod>const& rhs)
      |                                                                                        ^
a.cc:76:51: error: 'constexpr auto lib::operator+(int, const int&)' must have an argument of class or enumerated type
   76 |         template<std::uint64_t Mod>constexpr auto operator+(modnum<Mod> lhs, modnum<Mod>const& rhs)
      |                                                   ^~~~~~~~
a.cc:80:18: error: 'std::uint64_t' has not been declared
   80 |         template<std::uint64_t Mod>constexpr auto operator-(modnum<Mod> lhs, modnum<Mod>const& rhs)
      |                  ^~~
a.cc:80:68: error: 'Mod' was not declared in this scope
   80 |         template<std::uint64_t Mod>constexpr auto operator-(modnum<Mod> lhs, modnum<Mod>const& rhs)
      |                                                                    ^~~
a.cc:80:71: error: template argument 1 is invalid
   80 |         template<std::uint64_t Mod>constexpr auto operator-(modnum<Mod> lhs, modnum<Mod>const& rhs)
      |                                                                       ^
a.cc:80:85: error: 'Mod' was not declared in this scope
   80 |         template<std::uint64_t Mod>constexpr auto operator-(modnum<Mod> lhs, modnum<Mod>const& rhs)
      |                                                                                     ^~~
a.cc:80:88: error: template argument 1 is invalid
   80 |         template<std::uint64_t Mod>constexpr auto operator-(modnum<Mod> lhs, modnum<Mod>const& rhs)
      |                                                                                        ^
a.cc:80:51: error: 'constexpr auto lib::operator-(int, const int&)' must have an argument of class or enumerated type
   80 |         template<std::uint64_t Mod>constexpr auto operator-(modnum<Mod> lhs, modnum<Mod>const& rhs)
      |                                                   ^~~~~~~~
a.cc:84:18: error: 'std::uint64_t' has not been declared
   84 |         template<std::uint64_t Mod>constexpr auto operator*(modnum<Mod> lhs, modnum<Mod>const& rhs)
      |                  ^~~
a.cc:84:68: error: 'Mod' was not declared in this scope
   84 |         template<std::uint64_t Mod>constexpr auto operator*(modnum<Mod> lhs, modnum<Mod>const& rhs)
      |                                                                    ^~~
a.cc:84:71: error: template argument 1 is invalid
   84 |         template<std::uint64_t Mod>constexpr auto operator*(modnum<Mod> lhs, modnum<Mod>const& rhs)
      |                                                                       ^
a.cc:84:85: error: 'Mod' was not declared in this scope
   84 |         template<std::uint64_t Mod>constexpr auto operator*(modnum<Mod> lhs, modnum<Mod>const& rhs)
      |                                                                                     ^~~
a.cc:84:88: error: template argument 1 is invalid
   84 |         template<std::uint64_t Mod>constexpr auto operator*(modnum<Mod> lhs, modnum<Mod>const& rhs)
      |                                                                                        ^
a.cc:84:51: error: 'constexpr auto lib::operator*(int, const int&)' must have an argument of class or enumerated type
   84 |         template<std::uint64_t Mod>constexpr auto operator*(modnum<Mod> lhs, modnum<Mod>const& rhs)
      |                                                   ^~~~~~~~
a.cc:88:18: error: 'std::uint64_t' has not been declared
   88 |         template<std::uint64_t Mod>constexpr auto operator/(modnum<Mod> lhs, modnum<Mod>const& rhs)
      |                  ^~~
a.cc:88:68: error: 'Mod' was not declared in this scope
   88 |         template<std::uint64_t Mod>constexpr auto operator/(modnum<Mod> lhs, modnum<Mod>const& rhs)
      |                                                                    ^~~
a.cc:88:71: error: template argument 1 is invalid
   88 |         template<std::uint64_t Mod>constexpr auto operator/(modnum<Mod> lhs, modnum<Mod>const& rhs)
      |                                                                       ^
a.cc:88:85: error: 'Mod' was not declared in this scope
   88 |         template<std::uint64_t Mod>constexpr auto operator/(modnum<Mod> lhs, modnum<Mod>const& rhs)
      |                                                                                     ^~~
a.cc:88:88: error: template argument 1 is invalid
   88 |         template<std::uint64_t Mod>constexpr auto operator/(modnum<Mod> lhs, modnum<Mod>const& rhs)
      |                                                                                        ^
a.cc:88:51: error: 'constexpr auto lib::operator/(int, const int&)' must have an argument of class or enumerated type
   88 |         template<std::uint64_t Mod>constexpr auto operator/(modnum<Mod> lhs, modnum<Mod>const& rhs)
      |                                                   ^~~~~~~~
a.cc:93:18: error: 'std::uint64_t' has not been declared
   93 |         template<std::uint64_t Mod>constexpr auto inverse(modnum<Mod>const& base)
      |                  ^~~
a.cc:93:66: error: 'Mod' was not declared in this scope
   93 |         template<std::uint64_t Mod>constexpr auto inverse(modnum<Mod>const& base)
      |                                                                  ^~~
a.cc:93:69: error: template argument 1 is invalid
   93 |         template<std::uint64_t Mod>constexpr auto inverse(modnum<Mod>const& base)
      |                                                                     ^
a.cc: In function 'constexpr auto lib::inverse(const int&)':
a.cc:95:34: error: 'Mod' was not declared in this scope
   95 |                 return pow(base, Mod - 2);
      |                                  ^~~
a.cc: At global scope:
a.cc:172:34: error: 'int64_t' is not a member of 'std'; did you mean 'int64_t'?
  172 |                 std::vector<std::int64_t> tree;
      |                                  ^~~~~~~
In file included from /usr/include/x86_64-linux-gnu/sys/types.h:155,
                 from /usr/include/stdlib.h:514,
                 from /usr/include/c++/14/cstdlib:79,
                 from /usr/include/c++/14/ext/string_conversions.h:43,
                 from /usr/include/c++/14/bits/basic_string.h:4154,
                 from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/x86_64-linux-gnu/bits/stdint-intn.h:27:19: note: 'int64_t' declared here
   27 | typedef __int64_t int64_t;
      |                   ^~~~~~~
a.cc:172:41: error: template argument 1 is invalid
  172 |                 std::vector<std::int64_t> tree;
      |                                         ^
a.cc:172:41: error: template argument 2 is invalid
a.cc:179:48: error: 'std::int64_t' has not been declared
  179 |                 void change(std::size_t index, std::int64_t val)
      |                                                ^~~
a.cc:184:22: error: 'int64_t' in namespace 'std' does not name a type
  184 |                 std::int64_t get(std::size_t left, std::size_t right)//[left, right]の範囲
      |                      ^~~~~~~
a.cc:199:22: error: 'int64_t' in namespace 'std' does not name a type
  199 |                 std::int64_t change(std::size_t index, std::int64_t val, std::size_t dep)
      |                      ^~~~~~~
a.cc:216:22: error: 'int64_t' in namespace 'std' does not name a type
  216 |                 std::int64_t get(std::size_t a, std::size_t b, std::size_t left, std::size_t right, std::size_t dep)
      |                      ^~~~~~~
a.cc: In member function 'void lib::segtree::change(std::size_t, int)':
a.cc:181:31: error: no matching function for call to 'lib::segtree::change(std::size_t&, int&, int)'
  181 |                         change(index, val, 0);
      |                         ~~~~~~^~~~~~~~~~~~~~~
a.cc:179:22: note: candidate: 'void lib::segtree::change(std::size_t, int)'
  179 |                 void change(std::size_t index, std::int64_t val)
      |                      ^~~~~~
a.cc:179:22: note:   candida