// #pragma GCC target("avx") // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") #include using namespace std; #define rep(i,n) for(int i = 0; i < (int)n; i++) #define FOR(n) for(int i = 0; i < (int)n; i++) #define repi(i,a,b) for(int i = (int)a; i < (int)b; i++) #define all(x) x.begin(),x.end() //#define mp make_pair #define vi vector #define vvi vector #define vvvi vector #define vvvvi vector #define pii pair #define vpii vector> template void chmax(T &a, const T &b) {a = (a > b? a : b);} template void chmin(T &a, const T &b) {a = (a < b? a : b);} using ll = long long; using ld = long double; using ull = unsigned long long; const ll INF = numeric_limits::max() / 2; const ld pi = 3.1415926535897932384626433832795028; const ll mod = 998244353; int dx[] = {1, 0, -1, 0, -1, -1, 1, 1}; int dy[] = {0, 1, 0, -1, -1, 1, -1, 1}; #define int long long template< typename G > struct Namori { const G &g; vector< int > in; Namori(const G &g) : g(g), in(g.size(), 0) {} void decomposition(vector< int > &loop, vector< vector< int > > &forest) { int N = (int) in.size(); for(int i = 0; i < N; i++) { in[i] = g[i].size(); } forest.resize(N); queue< int > que; vector< bool > v(N, 0); for(int i = 0; i < N; i++) { if(in[i] == 1) { que.emplace(i); v[i] = true; } } while(!que.empty()) { int idx = que.front(); que.pop(); for(auto &to : g[idx]) { if(v[to.first]) continue; --in[to.first]; forest[to.first].push_back(idx); forest[idx].push_back(to.first); if(in[to.first] > 1) continue; que.emplace(to.first); v[to.first] = true; } } function< void(int) > dfs = [&](int idx) { loop.push_back(idx); for(auto &to : g[idx]) { if(v[to.first]) continue; v[to.first] = true; dfs(to.first); } }; for(int i = 0; i < N; i++) { if(v[i]) continue; v[i] = true; dfs(i); break; } } }; void solve() { int n; cin >> n; vi a(n), b(n); vector g(n); FOR(n) { cin >> a[i] >> b[i]; --a[i]; --b[i]; g[a[i]].emplace_back(b[i], i); g[b[i]].emplace_back(a[i], i); } Namori> namori(g); vi loop; vvi forest; namori.decomposition(loop, forest); vector in_loop(n, false); for(auto e : loop) in_loop[e] = true; vi ans(n); vector done(n, false); auto dfs = [&](int v, int p, auto self) -> void { done[v] = true; bool flag = false; for(auto e : g[v]) if(!done[e.first] && e.first != p && in_loop[e.first]) { ans[e.second] = v; flag = true; self(e.first, v, self); } if(!flag) { for(auto e : g[v]) if(e.first != p) { ans[e.second] = v; return; } } }; dfs(loop[0], -1, dfs); vi end; FOR(n) if(g[i].size() == 1) end.push_back(i); for(int now : end) { while(!in_loop[now]) { in_loop[now] = true; for(auto e : g[now]) if(!in_loop[e.first]) { ans[e.second] = now; now = e.first; break; } } } FOR(n) { if(ans[i] == a[i]) cout << "->" << endl; else cout << "<-" << endl; } } signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); return 0; }