Language: C++

#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	int N, M, T;
	cin >> N >> M >> T;
	if(T == 1) {
		vector< vector<uint64_t> > bits(50000, vector<uint64_t>(50000/64+1, 0));
		for(int i = 0; i < N; i++) bits[i][i>>6] |= 1ULL<<(i&63);
		for(int j = 0; j < N; j++)
			for(int i = N; i < (N/64+1)*64; i++) bits[j][i>>6] |= 1ULL<<(i&63);
		vector< pair<int, int> > bal(M);
		int final = -1;
		for(int i = 0; i < M; i++) {
			int x, y;
			cin >> x >> y;
			bal[i] = {--x, --y};
			if(final != -1) continue;
			uint64_t * __restrict ptr_x = &(bits[x][0]);
			uint64_t * __restrict ptr_y = &(bits[y][0]);
			uint64_t * __restrict ptr_fin = ptr_x + (N/64+1);
			uint64_t done = -1;
			for(; ptr_x != ptr_fin; ptr_x++, ptr_y++) {
				uint64_t v = *ptr_x | *ptr_y;
				*ptr_x = *ptr_y = v;
				done &= v;
			}
			if(!(~done)) final = x;
		}
		if(final == -1) {
			cout << "-1\n";
			return 0;
		}
		vector<int> max_id(N, -1);
		max_id[final] = M;
		string ans;
		for(int i = M-1; i >= 0; i--) {
			int x = bal[i].first, y = bal[i].second;
			if(max_id[x] == -1 && max_id[y] == -1)
				ans += '^';
			else if(max_id[x] != -1 && max_id[y] != -1)
				ans += (max_id[x] > max_id[y]) ? '^' : 'v';
			else if(max_id[x] == -1) {
				ans += 'v';
				max_id[x] = i;
			}
			else {
				ans += '^';
				max_id[y] = i;
			}
		}
		reverse(begin(ans), end(ans));
		cout << ans << "\n";
		return 0;
	}
	// T == 2
	if(1LL*N*(N-1) > M) {
		vector<int> cnt_bal(N, 0);
		for(int i = 0; i < M; i++) {
			cnt_bal[bal[i].first]++;
			cnt_bal[bal[i].second]++;
		}
		for(int i = 0; i < N; i++) if(cnt_bal[i] < N-1) {
			vector<char> adj(N, 0);
			adj[i] = 1;
			for(int j = 0; j < M; j++) {
				if(bal[j].first == i) adj[bal[j].second] = 1;
				if(bal[j].second == i) adj[bal[j].first] = 1;
			}
			for(int j = 0; j < N; j++) if(!adj[j]) {
				string ans;
				for(int k = 0; k < M; k++) {
					if(bal[k].first == i || bal[k].first == j) ans += '^';
					else ans += 'v';
				}
				cout << ans << "\n";
				return 0;
			}
			break;
		}
		return 0;
	}
}


Compiler output:
a.cc: In function 'int main()':
a.cc:13:32: error: 'uint64_t' was not declared in this scope
   13 |                 vector< vector<uint64_t> > bits(50000, vector<uint64_t>(50000/64+1, 0));
      |                                ^~~~~~~~
a.cc:5:1: note: 'uint64_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
    4 | #include <algorithm>
  +++ |+#include <cstdint>
    5 | using namespace std;
a.cc:13:40: error: template argument 1 is invalid
   13 |                 vector< vector<uint64_t> > bits(50000, vector<uint64_t>(50000/64+1, 0));
      |                                        ^
a.cc:13:40: error: template argument 2 is invalid
a.cc:13:42: error: template argument 1 is invalid
   13 |                 vector< vector<uint64_t> > bits(50000, vector<uint64_t>(50000/64+1, 0));
      |                                          ^
a.cc:13:42: error: template argument 2 is invalid
a.cc:13:71: error: template argument 2 is invalid
   13 |                 vector< vector<uint64_t> > bits(50000, vector<uint64_t>(50000/64+1, 0));
      |                                                                       ^
a.cc:13:87: error: expression list treated as compound expression in initializer [-fpermissive]
   13 |                 vector< vector<uint64_t> > bits(50000, vector<uint64_t>(50000/64+1, 0));
      |                                                                                       ^
a.cc:14:48: error: invalid types 'int[int]' for array subscript
   14 |                 for(int i = 0; i < N; i++) bits[i][i>>6] |= 1ULL<<(i&63);
      |                                                ^
a.cc:16:66: error: invalid types 'int[int]' for array subscript
   16 |                         for(int i = N; i < (N/64+1)*64; i++) bits[j][i>>6] |= 1ULL<<(i&63);
      |                                                                  ^
a.cc:24:36: error: expected primary-expression before '__restrict'
   24 |                         uint64_t * __restrict ptr_x = &(bits[x][0]);
      |                                    ^~~~~~~~~~
a.cc:25:36: error: expected primary-expression before '__restrict'
   25 |                         uint64_t * __restrict ptr_y = &(bits[y][0]);
      |                                    ^~~~~~~~~~
a.cc:26:36: error: expected primary-expression before '__restrict'
   26 |                         uint64_t * __restrict ptr_fin = ptr_x + (N/64+1);
      |                                    ^~~~~~~~~~
a.cc:27:33: error: expected ';' before 'done'
   27 |                         uint64_t done = -1;
      |                                 ^~~~~
      |                                 ;
a.cc:28:31: error: 'ptr_x' was not declared in this scope
   28 |                         for(; ptr_x != ptr_fin; ptr_x++, ptr_y++) {
      |                               ^~~~~
a.cc:28:40: error: 'ptr_fin' was not declared in this scope
   28 |                         for(; ptr_x != ptr_fin; ptr_x++, ptr_y++) {
      |                                        ^~~~~~~
a.cc:28:58: error: 'ptr_y' was not declared in this scope
   28 |                         for(; ptr_x != ptr_fin; ptr_x++, ptr_y++) {
      |                                                          ^~~~~
a.cc:29:41: error: expected ';' before 'v'
   29 |                                 uint64_t v = *ptr_x | *ptr_y;
      |                                         ^~
      |                                         ;
a.cc:30:51: error: 'v' was not declared in this scope
   30 |                                 *ptr_x = *ptr_y = v;
      |                                                   ^
a.cc:31:33: error: 'done' was not declared in this scope
   31 |                                 done &= v;
      |                                 ^~~~
a.cc:33:31: error: 'done' was not declared in this scope
   33 |                         if(!(~done)) final = x;
      |                               ^~~~
a.cc:65:33: error: 'bal' was not declared in this scope
   65 |                         cnt_bal[bal[i].first]++;
      |                                 ^~~
a.cc:72:36: error: 'bal' was not declared in this scope
   72 |                                 if(bal[j].first == i) adj[bal[j].second] = 1;
      |                                    ^~~
a.cc:73:36: error: 'bal' was not declared in this scope
   73 |                                 if(bal[j].second == i) adj[bal[j].first] = 1;
      |                                    ^~~
a.cc:78:44: error: 'bal' was not declared in this scope
   78 |                                         if(bal[k].first == i || bal[k].first == j) ans += '^';
      |                                            ^~~