## https://yukicoder.me/problems/no/2301 from collections import deque class UnionFind: """ UnionFindの基本的な処理を実装したクラス """ def __init__(self, size): self.root = [i for i in range(size)] self.size = [1] * size def get_root(self, v): if v == self.root[v]: return v else: old_root = self.root[v] new_root = self.get_root(old_root) self.root[v] = new_root return new_root def merge(self, u, v): root_u = self.get_root(u) root_v = self.get_root(v) if root_u == root_v: return False if self.size[root_u] >= self.size[root_v]: self.size[root_u] += self.size[root_v] self.root[root_v] = root_u self.root[v] = root_u else: self.size[root_v] += self.size[root_u] self.root[root_u] = root_v self.root[u] = root_v return True def main(): N = int(input()) edges = [] edges_map = {} for i in range(N): a, b = map(int, input().split()) edges.append((a - 1, b - 1)) edges_map[(a - 1, b - 1)] = i # union findを使って木の構成に邪魔なedgeを取り出す uf = UnionFind(N) next_edges = [[] for _ in range(N)] fales = [] for a, b in edges: if uf.merge(a, b): next_edges[a].append(b) next_edges[b].append(a) else: fales.append((a, b)) start = fales[0][0] parents = [-2] * N parents[start] = -1 queue = deque() queue.append(start) while len(queue) > 0: v = queue.popleft() for w in next_edges[v]: if w == parents[v]: continue parents[w] = v queue.append(w) parents[start] = fales[0][1] answers = ["" for _ in range(N)] for i in range(N): j = parents[i] if (i, j) in edges_map: answers[edges_map[(i, j)]] = "->" elif (j, i) in edges_map: answers[edges_map[(j, i)]] = "<-" for ans in answers: print(ans) if __name__ == "__main__": main()