#include #include #include #include #include using namespace std; int main(){ int N; cin >> N; vector A(N); vector B(N); for (int i = 0; i < N; i++){ cin >> A[i] >> B[i]; A[i]--; B[i]--; } map, int> mp; for (int i = 0; i < N; i++){ mp[pair(A[i], B[i])] = i; } vector> graph(N, vector(0)); for (int i = 0; i < N; i++){ graph[A[i]].push_back(B[i]); graph[B[i]].push_back(A[i]); } vector tag(N, true); vector count(N, 0); for (int i = 0; i < N; i++){ count[A[i]]++; count[B[i]]++; } //ループ以外の辺を削除するために BFS vector isvisited(N, false); queue que; for (int i = 0; i < N; i++){ if (count[i] == 1) que.push(i); } while(que.size()){ int p = que.front(); que.pop(); if (isvisited[p]){ continue; } isvisited[p] = true; for (int x: graph[p]){ tag[mp[pair(min(p, x), max(p, x))]] = false; count[x]--; if (count[x] == 1){ que.push(x); } } } vector ans(N); // ループのみのグラフ vector> graph2(N, vector(0)); int start = -1; for (int i = 0; i < N; i++){ if (tag[i]){ start = A[i]; graph2[A[i]].push_back(B[i]); graph2[B[i]].push_back(A[i]); } } // ループの中だけをみる for (int i = 0; i < N; i++) isvisited[i] = false; int now = start; while(true){ isvisited[now] = true; bool seen = false; for (int i = 0; i < graph2[now].size(); i++){ if (isvisited[graph2[now][i]]){ continue; } seen = true; if (graph2[now][i] > now){ ans[mp[pair(now, graph2[now][i])]] = 1; } else{ ans[mp[pair(graph2[now][i], now)]] = 0; } now = graph2[now][i]; break; } if (!seen){ for (int i = 0; i < graph2[now].size(); i++){ if (graph2[now][i] == start){ if (graph2[now][i] > now){ ans[mp[pair(now, graph2[now][i])]] = 1; } else{ ans[mp[pair(graph2[now][i], now)]] = 0; } } } break; } } // ループの外だけで BFS for (int i = 0; i < N; i++){ if (isvisited[i]){ que.push(i); while(que.size()){ int p = que.front(); que.pop(); for (int x: graph[p]){ if (isvisited[x]) continue; isvisited[x] = true; if (p > x){ ans[mp[pair(x, p)]] = 1; } else{ ans[mp[pair(p, x)]] = 0; } que.push(x); } } } } for (int i = 0; i < N; i++){ if (ans[i] == 1) cout << "->" << endl; else cout << "<-" << endl; } return 0; }