結果
問題 | No.1605 Matrix Shape |
ユーザー | 👑 rin204 |
提出日時 | 2021-07-16 22:06:31 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,748 bytes |
コンパイル時間 | 533 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 102,784 KB |
最終ジャッジ日時 | 2024-07-06 09:21:11 |
合計ジャッジ時間 | 6,252 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 50 ms
70,528 KB |
testcase_01 | AC | 50 ms
71,296 KB |
testcase_02 | AC | 42 ms
66,688 KB |
testcase_03 | AC | 50 ms
71,680 KB |
testcase_04 | AC | 46 ms
69,632 KB |
testcase_05 | WA | - |
testcase_06 | AC | 50 ms
71,808 KB |
testcase_07 | AC | 42 ms
66,944 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 43 ms
67,200 KB |
testcase_12 | WA | - |
testcase_13 | RE | - |
testcase_14 | WA | - |
testcase_15 | AC | 42 ms
66,816 KB |
testcase_16 | AC | 42 ms
67,072 KB |
testcase_17 | AC | 41 ms
66,688 KB |
testcase_18 | AC | 42 ms
66,944 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 232 ms
102,528 KB |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | AC | 162 ms
92,928 KB |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | AC | 208 ms
93,568 KB |
testcase_34 | AC | 170 ms
96,088 KB |
testcase_35 | AC | 186 ms
96,640 KB |
testcase_36 | AC | 143 ms
94,108 KB |
ソースコード
n = int(input()) max_ = 2 * 10 ** 5 edges = [[] for _ in range(max_)] in_cnt = [0] * max_ out_cnt = [0] * max_ for _ in range(n): h, w = map(int, input().split()) h -= 1 w -= 1 edges[h].append(w) in_cnt[h] += 1 out_cnt[w] += 1 s = -1 g = -1 for j, (i, o) in enumerate(zip(in_cnt, out_cnt)): if i == o: continue if i == o + 1: if s == -1: s = j else: print(0) exit() elif i + 1 == o: if g == -1: g = j else: print(0) exit() else: print(0) exit() if s == g == -1: stack = [h] used = [False] * max_ used[h] = True while stack: pos = stack.pop() for npos in edges[pos]: if used[npos]: continue used[npos] = True for i in range(max_): if not used[i] and in_cnt[i] != 0: print(0) exit() ans = 0 for e in edges: ans += len(set(e)) print(ans) exit() stack = [s] used = [False] * max_ used[s] = True while stack: pos = stack.pop() for npos in edges[pos]: if used[npos]: continue used[npos] = True for i in range(max_): if not used[i] and in_cnt[i] != 0: print(0) exit() cnt = 0 used = [False] * n stack = [s] used[s] = True while stack: pos = stack.pop() for npos in edges[pos]: if used[npos]: continue if npos == g: cnt += 1 continue used[npos] = True stack.append(npos) l = 0 for e in edges: if g in e: l += 1 if cnt == 1: print(max(1, l - 1)) else: print(l)