結果
問題 | No.768 Tapris and Noel play the game on Treeone |
ユーザー | ninja-kid |
提出日時 | 2023-02-24 01:58:32 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,586 bytes |
コンパイル時間 | 267 ms |
コンパイル使用メモリ | 82,428 KB |
実行使用メモリ | 103,424 KB |
最終ジャッジ日時 | 2024-07-23 18:23:46 |
合計ジャッジ時間 | 9,207 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
20evil_special_uni1.txt | WA | - |
20evil_special_uni2.txt | WA | - |
ソースコード
#!/usr/bin/env python3 from bisect import bisect_left, bisect_right from collections import deque from itertools import permutations from sys import setrecursionlimit dpos4 = ((1, 0), (0, 1), (-1, 0), (0, -1)) dpos8 = ((0, -1), (1, -1), (1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1)) mod1 = 10**9 + 7 mod2 = 998244353 inf = 1 << 60 def main(): N = int(input()) edges = [[] for _ in range(N)] for _ in range(N - 1): u, v = map(int, input().split()) u -= 1 v -= 1 edges[u].append(v) edges[v].append(u) dp1 = [True] * N dp2 = [True] * N setrecursionlimit(10**6) def dfs1(fr, prev=-1): val = False for to in edges[fr]: if to == prev: continue dfs1(to, fr) val |= dp1[to] dp1[fr] = not val def dfs2(fr, prev=-1): val = False for to in edges[fr]: val |= dp1[to] dp2[fr] = not val L = len(edges[fr]) lval = [False] * (L + 1) rval = [False] * (L + 1) for i in range(L): to = edges[fr][i] lval[i + 1] = lval[i] or dp1[to] j = L - 1 - i to = edges[fr][j] rval[j] = rval[j + 1] or dp1[to] for i in range(L): to = edges[fr][i] if to == prev: continue dp1[fr] = not (lval[i] or rval[i + 1]) dfs2(to, fr) dfs1(0) dfs2(0) print(sum(dp2)) print(*(i + 1 for i in range(N) if dp2[i])) if __name__ == "__main__": main()