Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

void ch(int &x, int &y){
    if(y < x){
        int tmp = y;
        y = x;
        x = tmp;
    }
}

int N, M, T;
vector<int>x, y;

void solve1(){
    
}

void solve2(){
    if(N == 2){
        cout << -1 << "\n";
        return;
    }
    vector<vector<int>>graph(N+1, vector<int>());
    for (int i = 0; i < M; ++i) {
        graph[x[i]].push_back(i);
        graph[y[i]].push_back(i);
    }

    x1 = x[0];
    y1 = y[0] + 1;
    if(y1 == N + 1) {
        if(x1 == 1) y1 = 2;
        else y1 = 1;
    }
    ch(x1, y1);

    // 次で衝突する場合は進路転換
    for (int i = 0; i < M; ++i) {
        auto iter1 = upper_bound(graph[x1].begin(), graph[x1].end(), i);
        auto iter2 = upper_bound(graph[y1].begin(), graph[y1].end(), i);
        if(iter1 != graph[x1].end() && iter2 != graph[y1].end() && (*iter1 == *iter2)){
            if(x[i] == x1){
                cout << "v";
                x1 = y[i];
            } else if(y[i] == y1){
                cout << "^";
                y1 = x[i];
            } else if(y[i] == x1){
                cout << "^";
                x1 = x[i];
            } else if(x[i] == y1){
                cout << "v";
                y1 = y[i];
            }
        } else {
            if (y1[i] == y || y1[i] == x) {
                cout << "v";
            } else {
                cout << "^";
            }
        }
        ch();
    }
}

int main() {
    cin >> N >> M >> T;
    x.resize(M); y.resize(M);
    for (int i = 0; i < M; ++i) {
        cin >> x[i] >> y[i];
    }
    if (T == 1) solve1();
    else solve2();
    return 0;
}

Compiler output:
a.cc: In function 'void solve2()':
a.cc:31:5: error: 'x1' was not declared in this scope; did you mean 'y1'?
   31 |     x1 = x[0];
      |     ^~
      |     y1
a.cc:32:8: error: assignment of function 'double y1(double)'
   32 |     y1 = y[0] + 1;
      |     ~~~^~~~~~~~~~
a.cc:33:11: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   33 |     if(y1 == N + 1) {
      |        ~~~^~~~~~~~
a.cc:34:24: error: assignment of function 'double y1(double)'
   34 |         if(x1 == 1) y1 = 2;
      |                     ~~~^~~
a.cc:35:17: error: assignment of function 'double y1(double)'
   35 |         else y1 = 1;
      |              ~~~^~~
a.cc:42:40: error: invalid conversion from 'double (*)(double) noexcept' to 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-fpermissive]
   42 |         auto iter2 = upper_bound(graph[y1].begin(), graph[y1].end(), i);
      |                                        ^~
      |                                        |
      |                                        double (*)(double) noexcept
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:1128:28: note:   initializing argument 1 of 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >; reference = std::vector<int>&; size_type = long unsigned int]'
 1128 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
a.cc:42:59: error: invalid conversion from 'double (*)(double) noexcept' to 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-fpermissive]
   42 |         auto iter2 = upper_bound(graph[y1].begin(), graph[y1].end(), i);
      |                                                           ^~
      |                                                           |
      |                                                           double (*)(double) noexcept
/usr/include/c++/14/bits/stl_vector.h:1128:28: note:   initializing argument 1 of 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >; reference = std::vector<int>&; size_type = long unsigned int]'
 1128 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
a.cc:43:55: error: invalid conversion from 'double (*)(double) noexcept' to 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-fpermissive]
   43 |         if(iter1 != graph[x1].end() && iter2 != graph[y1].end() && (*iter1 == *iter2)){
      |                                                       ^~
      |                                                       |
      |                                                       double (*)(double) noexcept
/usr/include/c++/14/bits/stl_vector.h:1128:28: note:   initializing argument 1 of 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >; reference = std::vector<int>&; size_type = long unsigned int]'
 1128 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
a.cc:47:28: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   47 |             } else if(y[i] == y1){
a.cc:49:20: error: assignment of function 'double y1(double)'
   49 |                 y1 = x[i];
a.cc:53:28: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   53 |             } else if(x[i] == y1){
a.cc:55:20: error: assignment of function 'double y1(double)'
   55 |                 y1 = y[i];
a.cc:58:21: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   58 |             if (y1[i] == y || y1[i] == x) {
      |                     ^
a.cc:58:23: error: no match for 'operator==' (operand types are 'double(double) noexcept' and 'std::vector<int>')
   58 |             if (y1[i] == y || y1[i] == x) {
      |                 ~~~~~ ^~ ~
      |                     |    |
      |                     |    std::vector<int>
      |                     double(double) noexcept
In file included from /usr/include/c++/14/regex:68,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:181:
/usr/include/c++/14/bits/regex.h:1103:5: note: candidate: 'template<class _BiIter> bool std::__cxx11::operator==(const sub_match<_BiIter>&, const sub_match<_BiIter>&)'
 1103 |     operator==(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1103:5: note:   template argument deduction/substitution failed:
a.cc:58:26: note:   mismatched types 'const std::__cxx11::sub_match<_BiIter>' and 'double(double) noexcept'
   58 |             if (y1[i] == y || y1[i] == x) {
      |                          ^
/usr/include/c++/14/bits/regex.h:1199:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator==(__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&, const sub_match<_BiIter>&)'
 1199 |     operator==(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1199:5: note:   template argument deduction/substitution failed:
a.cc:58:26: note:   mismatched types 'std::__cxx11::__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>' and 'double(double) noexcept'
   58 |             if (y1[i] == y || y1[i] == x) {
      |                          ^
/usr/include/c++/14/bits/regex.h:1274:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator==(const sub_match<_BiIter>&, __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&)'
 1274 |     operator==(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1274:5: note:   template argument deduction/substitution failed:
a.cc:58:26: note:   mismatched types 'const std::__cxx11::sub_match<_BiIter>' and 'double(double) noexcept'
   58 |             if (y1[i] == y || y1[i] == x) {
      |                          ^
/usr/include/c++/14/bits/regex.h:1366:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator==(const typename std::iterator_traits<_Iter>::value_type*, const sub_match<_BiIter>&)'
 1366 |     operator==(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1366:5: note:   template argument deduction/substitution failed:
a.cc:58:26: note:   'std::vector<int>' is not derived from 'const std::__cxx11::sub_match<_BiIter>'
   58 |             if (y1[i] == y || y1[i] == x) {
      |                          ^
/usr/include/c++/14/bits/regex.h:1441:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator==(const sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type*)'
 1441 |     operator==(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1441:5: note:   template argument deduction/substitution failed:
a.cc:58:26: note:   mismatched types 'const std::__cxx11::sub_match<_BiIter>' and 'double(double) noexcept'
   58 |             if (y1[i] == y || y1[i] == x) {
      |                          ^
/usr/include/c++/14/bits/regex.h:1534:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator==(const typename std::iterator_traits<_Iter>::value_type&, const sub_match<_BiIter>&)'
 1534 |     operator==(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1534:5: note:   template argument deduction/substitution failed:
a.cc:58:26: note:   'std::vector<int>' is not derived from 'const std::__cxx11::sub_match<_BiIter>'
   58 |             if (y1[i] == y || y1[i] == x) {
      |                          ^
/usr/include/c++/14/bits/regex.h:1613:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator==(const sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type&)'
 1613 |     operator==(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1613:5: note:   template argument deduction/substitution failed:
a.cc:58:26: note:   mismatched types 'const std::__cxx11::sub_match<_BiIter>' and 'double(double) noexcept'
   58 |             if (y1[i] == y || y1[i] == x) {
      |                          ^
/usr/include/c++/14/bits/regex.h:2186:5: note: candidate: 'template<class _Bi_iter, class _Alloc> bool std::__cxx11::operator==(const match_results<_BiIter, _Alloc>&, const match_results<_BiIter, _Alloc>&)'
 2186 |     operator==(const match_results<_Bi_iter, _Alloc>& __m1,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:2186:5: note:   template argument deduction/substitution failed:
a.cc:58:26: note:   mismatched types 'const std::__cxx11::match_results<_BiIter, _Alloc>' and 'double(double) noexcept'
   58 |             if (y1[i] == y || y1[i] == x) {
      |                          ^
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/bits/stl_pair.h:1033:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator==(const pair<_T1, _T2>&, const pair<_T1, _T2>&)'
 1033 |     operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1033:5: note:   template argument deduction/substitution failed:
a.cc:58:26: note:   mismatched types 'const std::pair<_T1, _T2>' and 'double(double) noexcept'
   58 |             if (y1[i] == y || y1[i] == x) {
      |                          ^
In file included from /usr/include/c++/14/bits/stl_algobase.h:67:
/usr/include/c++/14/bits/stl_iterator.h:441:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator==(co