#include using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() using ll = long long; constexpr int INF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr double EPS = 1e-8; constexpr int MOD = 998244353; // constexpr int MOD = 1000000007; constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1}; constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1}; constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1}; template inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; } template inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << fixed << setprecision(20); } } iosetup; struct UnicyclicGraph { std::vector is_in_loop; std::vector belong, mapping, loop; std::vector> invs; std::vector>> forest; explicit UnicyclicGraph(const int n) : is_in_loop(n, false), belong(n, -1), mapping(n, -1), n(n), graph(n) {} void add_edge(const int src, const int dst) { const int id = srcs.size(); srcs.emplace_back(src); dsts.emplace_back(dst); graph[src].emplace_back(id); if (dst != src) [[likely]] graph[dst].emplace_back(id); } void build() { dfs(-1, 0); std::queue que; for (const int root : loop) { const int forest_id = forest.size(); belong[root] = forest_id; mapping[root] = 0; std::vector inv{root}; std::vector> tree(1); que.emplace(root); while (!que.empty()) { const int ver = que.front(); que.pop(); for (const int id : graph[ver]) { const int dst = destination(id, ver); if (belong[dst] == -1 && !is_in_loop[dst]) { const int idx = tree.size(); belong[dst] = forest_id; mapping[dst] = idx; inv.emplace_back(dst); tree[mapping[ver]].emplace_back(idx); tree.emplace_back(std::vector{mapping[ver]}); que.emplace(dst); } } } if (inv.size() == 1) { belong[root] = mapping[root] = -1; } else { invs.emplace_back(inv); forest.emplace_back(tree); } } } private: const int n; std::vector srcs, dsts; std::vector> graph; int destination(const int id, const int s) const { return (srcs[id] == s ? dsts : srcs)[id]; } bool dfs(const int prev_id, const int ver) { is_in_loop[ver] = true; loop.emplace_back(ver); for (const int id : graph[ver]) { if (id == prev_id) continue; const int dst = destination(id, ver); if (is_in_loop[dst]) { for (int i = loop.size() - 1; i >= 0; --i) { if (loop[i] == dst) { for (int j = 0; j < i; ++j) { is_in_loop[loop[j]] = false; } loop.erase(loop.begin(), std::next(loop.begin(), i)); return true; } } assert(false); } if (dfs(id, dst)) return true; } loop.pop_back(); is_in_loop[ver] = false; return false; } }; int main() { int n; cin >> n; UnicyclicGraph yuruyuri(n); map, int> mp; REP(id, n) { int a, b; cin >> a >> b; --a; --b; yuruyuri.add_edge(a, b); mp[{a, b}] = id; } yuruyuri.build(); vector> edges; edges.reserve(n); const int m = yuruyuri.invs.size(); REP(tr, m) { const auto dfs = [&](auto dfs, const int par, const int ver) -> void { for (const int e : yuruyuri.forest[tr][ver]) { if (e != par) { edges.emplace_back(yuruyuri.invs[tr][e], yuruyuri.invs[tr][ver]); dfs(dfs, ver, e); } } }; dfs(dfs, -1, 0); } const int lp = yuruyuri.loop.size(); REP(i, lp) edges.emplace_back(yuruyuri.loop[i], yuruyuri.loop[(i + 1) % lp]); vector ans(n); for (const auto& [u, v] : edges) { if (mp.contains({u, v})) { ans[mp[{u, v}]] = "->"; } else { ans[mp[{v, u}]] = "<-"; } } REP(i, n) cout << ans[i] << '\n'; return 0; }