Language: C++

#include <algorithm>
using namespace std;
int n, m, T;
#define Maxn 50010
int x[Maxn << 1], y[Maxn << 1];
bitset<Maxn> b[Maxn];
bool ap[Maxn];
int seq[Maxn << 1];
int to[Maxn], B[Maxn];

inline void rd(int &x)
{
	x = 0;
	char ch = getchar();
	while (ch < '0' || ch > '9')
		ch = getchar();
	while (ch >= '0' && ch <= '9')
	{
		x = x * 10 + ch - '0';
		ch = getchar();
	}
}

inline int gi()
{
	char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	int sum = 0;
	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
	return sum;
}

int main()
{
	rd(n);
	rd(m);
	rd(T);
	for (int i = 1; i <= m; ++i)
	{
		rd(x[i]);
		rd(y[i]);
	}
	if (T == 1)
	{
		for (int i = 1; i <= n; ++i)
			b[i][i] = 1;
		bitset<Maxn> res;
		for (int i = m; i >= 1; --i)
		{
			res = b[x[i]] | b[y[i]];
			b[x[i]] = b[y[i]] = res;
		}
		res = b[1];
		for (int i = 2; i <= n; ++i)
			res &= b[i];
		int flag = -1;
		for (int i = 1; i <= n; ++i)
			if (res[i])
			{
				flag = i;
				break;
			}
		if (flag == -1)
		{
			puts("-1");
			return 0;
		}
		ap[flag] = true;
		for (int i = m; i >= 1; --i)
		{
			if (ap[x[i]] == false && ap[y[i]] == false)
				seq[i] = 0;
			else if (ap[x[i]] == true && ap[y[i]] == true)
				seq[i] = 0;
			else if (ap[x[i]])
				seq[i] = 0;
			else
				seq[i] = 1;
			bool tmp = ap[x[i]] | ap[y[i]];
			ap[x[i]] = ap[y[i]] = tmp;
		}
		for (int i = 1; i <= m; ++i)
			if (seq[i] == 0)
				printf("^");
			else
				printf("v");
	}
	else
	{
		if (n == 2)
		{
			puts("-1");
			return 0;
		}
		for (int i = 1; i <= n; ++i)
		{
			B[i] = i;
			to[i] = 1;
		}
		for (int i = 1; i <= n; ++i)
		{
			B[i] = i;
			to[i] = 1;
		}
		for (int i = m; i >= 1; --i)
		{
			if (B[x[i]] == B[y[i]])
			{
				seq[i] = 0;
				continue;
			}
			if (to[B[x[i]]] >= 2)
			{
				seq[i] = 1;
				to[B[x[i]]]--;
				B[x[i]] = B[y[i]];
				to[B[y[i]]]++;
			}
			else
			{
				seq[i] = 0;
				to[B[y[i]]]--;
				B[y[i]] = B[x[i]];
				to[B[x[i]]]++;
			}
		}
		for (int i = 1; i <= m; ++i)
			if (seq[i] == 0)
				printf("^");
			else
				printf("v");
	}
	return 0;
}

Compiler output:
a.cc:6:1: error: 'bitset' does not name a type
    6 | bitset<Maxn> b[Maxn];
      | ^~~~~~
a.cc: In function 'void rd(int&)':
a.cc:14:19: error: 'getchar' was not declared in this scope
   14 |         char ch = getchar();
      |                   ^~~~~~~
a.cc:2:1: note: 'getchar' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
    1 | #include <algorithm>
  +++ |+#include <cstdio>
    2 | using namespace std;
a.cc: In function 'int gi()':
a.cc:26:18: error: 'getchar' was not declared in this scope
   26 |         char c = getchar();
      |                  ^~~~~~~
a.cc:26:18: note: 'getchar' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
a.cc: In function 'int main()':
a.cc:46:25: error: 'b' was not declared in this scope
   46 |                         b[i][i] = 1;
      |                         ^
a.cc:47:17: error: 'bitset' was not declared in this scope
   47 |                 bitset<Maxn> res;
      |                 ^~~~~~
a.cc:2:1: note: 'std::bitset' is defined in header '<bitset>'; this is probably fixable by adding '#include <bitset>'
    1 | #include <algorithm>
  +++ |+#include <bitset>
    2 | using namespace std;
a.cc:47:30: error: 'res' was not declared in this scope
   47 |                 bitset<Maxn> res;
      |                              ^~~
a.cc:50:31: error: 'b' was not declared in this scope
   50 |                         res = b[x[i]] | b[y[i]];
      |                               ^
a.cc:53:23: error: 'b' was not declared in this scope
   53 |                 res = b[1];
      |                       ^
a.cc:65:25: error: 'puts' was not declared in this scope
   65 |                         puts("-1");
      |                         ^~~~
a.cc:84:33: error: 'printf' was not declared in this scope
   84 |                                 printf("^");
      |                                 ^~~~~~
a.cc:84:33: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
a.cc:86:33: error: 'printf' was not declared in this scope
   86 |                                 printf("v");
      |                                 ^~~~~~
a.cc:86:33: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
a.cc:92:25: error: 'puts' was not declared in this scope
   92 |                         puts("-1");
      |                         ^~~~
a.cc:129:33: error: 'printf' was not declared in this scope
  129 |                                 printf("^");
      |                                 ^~~~~~
a.cc:129:33: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
a.cc:131:33: error: 'printf' was not declared in this scope
  131 |                                 printf("v");
      |                                 ^~~~~~
a.cc:131:33: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'