結果
問題 | No.2301 Namorientation |
ユーザー | kys |
提出日時 | 2023-05-13 17:06:34 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 917 ms / 3,000 ms |
コード長 | 2,703 bytes |
コンパイル時間 | 287 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 159,052 KB |
最終ジャッジ日時 | 2024-11-29 09:02:55 |
合計ジャッジ時間 | 22,294 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
52,480 KB |
testcase_01 | AC | 42 ms
52,736 KB |
testcase_02 | AC | 42 ms
52,608 KB |
testcase_03 | AC | 43 ms
52,864 KB |
testcase_04 | AC | 43 ms
52,480 KB |
testcase_05 | AC | 42 ms
52,608 KB |
testcase_06 | AC | 41 ms
52,864 KB |
testcase_07 | AC | 41 ms
52,736 KB |
testcase_08 | AC | 41 ms
52,480 KB |
testcase_09 | AC | 41 ms
52,480 KB |
testcase_10 | AC | 41 ms
52,480 KB |
testcase_11 | AC | 41 ms
52,864 KB |
testcase_12 | AC | 598 ms
117,384 KB |
testcase_13 | AC | 560 ms
113,568 KB |
testcase_14 | AC | 845 ms
143,004 KB |
testcase_15 | AC | 649 ms
121,920 KB |
testcase_16 | AC | 763 ms
134,016 KB |
testcase_17 | AC | 633 ms
119,736 KB |
testcase_18 | AC | 791 ms
135,508 KB |
testcase_19 | AC | 537 ms
112,080 KB |
testcase_20 | AC | 771 ms
134,224 KB |
testcase_21 | AC | 702 ms
121,524 KB |
testcase_22 | AC | 294 ms
140,320 KB |
testcase_23 | AC | 294 ms
139,472 KB |
testcase_24 | AC | 263 ms
128,876 KB |
testcase_25 | AC | 275 ms
140,804 KB |
testcase_26 | AC | 332 ms
159,052 KB |
testcase_27 | AC | 898 ms
143,172 KB |
testcase_28 | AC | 841 ms
143,552 KB |
testcase_29 | AC | 859 ms
143,412 KB |
testcase_30 | AC | 860 ms
143,556 KB |
testcase_31 | AC | 917 ms
142,912 KB |
ソースコード
def main(): from sys import stdin, setrecursionlimit # setrecursionlimit(1000000) input = stdin.readline def iinput(): return int(input()) def sinput(): return input().rstrip() def i0input(): return int(input()) - 1 def linput(): return list(input().split()) def liinput(): return list(map(int, input().split())) def miinput(): return map(int, input().split()) def li0input(): return list(map(lambda x: int(x) - 1, input().split())) def mi0input(): return map(lambda x: int(x) - 1, input().split()) INF = 1000000000000000000 MOD = 1000000007 class UnionFindTree: def __init__(self, initial_size:int) -> None: self.n_nodes = initial_size self.parents = [i for i in range(initial_size)] self.ranks = [0 for i in range(initial_size)] self.size = [1 for i in range(initial_size)] self.n_roots = initial_size def root(self, n:int) -> int: if self.parents[n] == n: return n else: self.parents[n] = self.root(self.parents[n]) return self.parents[n] def same(self, n:int, m:int) -> bool: return (self.root(n) == self.root(m)) def unite(self, n:int, m:int) -> None: if self.same(n, m): return self.n_roots -= 1 n, m = self.root(n), self.root(m) if self.ranks[n] < self.ranks[m]: self.parents[n] = m self.size[m] += self.size[n] else: self.parents[m] = n self.size[n] += self.size[m] if self.ranks[n] == self.ranks[m]: self.ranks[n] += 1 def get_roots(self) -> set: return set([self.root(x) for x in range(self.n_nodes)]) def count_roots(self) -> int: return self.n_roots def get_tree_size(self, n:int) -> int: return self.size[self.root(n)] N = iinput() g = [[] for _ in [0] * N] ans = [-1] * N uf = UnionFindTree(N) for i in range(N): a, b = mi0input() if uf.same(a, b): s = a ans[i] = '->' continue g[a].append((b, i, 0)) # <- g[b].append((a, i, 1)) # -> uf.unite(a, b) st = [s] seen = [False] * N seen[s] = True while st: u = st.pop() for v, idx, flg in g[u]: if seen[v]: continue seen[v] = True if flg: ans[idx] = '->' else: ans[idx] = '<-' st.append(v) for a in ans: print(a) main()