結果
問題 | No.768 Tapris and Noel play the game on Treeone |
ユーザー | ninja-kid |
提出日時 | 2023-02-24 02:02:13 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 736 ms / 2,000 ms |
コード長 | 1,617 bytes |
コンパイル時間 | 86 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 35,608 KB |
最終ジャッジ日時 | 2024-07-23 18:26:13 |
合計ジャッジ時間 | 11,554 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 31 ms
10,752 KB |
testcase_01 | AC | 30 ms
11,008 KB |
testcase_02 | AC | 29 ms
11,008 KB |
testcase_03 | AC | 33 ms
11,008 KB |
testcase_04 | AC | 37 ms
11,008 KB |
testcase_05 | AC | 36 ms
11,008 KB |
testcase_06 | AC | 34 ms
10,880 KB |
testcase_07 | AC | 435 ms
23,296 KB |
testcase_08 | AC | 231 ms
17,280 KB |
testcase_09 | AC | 263 ms
18,432 KB |
testcase_10 | AC | 199 ms
16,768 KB |
testcase_11 | AC | 736 ms
29,824 KB |
testcase_12 | AC | 688 ms
30,208 KB |
testcase_13 | AC | 653 ms
29,568 KB |
testcase_14 | AC | 645 ms
29,440 KB |
testcase_15 | AC | 714 ms
30,592 KB |
testcase_16 | AC | 704 ms
30,720 KB |
testcase_17 | AC | 733 ms
31,104 KB |
testcase_18 | AC | 662 ms
35,120 KB |
testcase_19 | AC | 674 ms
35,608 KB |
testcase_20 | AC | 659 ms
34,688 KB |
testcase_21 | AC | 641 ms
33,396 KB |
20evil_special_uni1.txt | AC | 690 ms
32,128 KB |
20evil_special_uni2.txt | AC | 657 ms
31,232 KB |
ソースコード
#!/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)) if sum(dp2): print(*(i + 1 for i in range(N) if dp2[i]), sep='\n') if __name__ == "__main__": main()