結果
問題 | No.1817 Reversed Edges |
ユーザー |
![]() |
提出日時 | 2022-01-21 22:08:27 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 478 ms / 2,000 ms |
コード長 | 1,152 bytes |
コンパイル時間 | 158 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 31,872 KB |
最終ジャッジ日時 | 2024-11-26 00:30:46 |
合計ジャッジ時間 | 8,932 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 23 |
ソースコード
import sys# sys.setrecursionlimit(200005)int1 = lambda x: int(x)-1pDB = lambda *x: print(*x, end="\n", file=sys.stderr)p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)def II(): return int(sys.stdin.readline())def LI(): return list(map(int, sys.stdin.readline().split()))def LLI(rows_number): return [LI() for _ in range(rows_number)]def LI1(): return list(map(int1, sys.stdin.readline().split()))def LLI1(rows_number): return [LI1() for _ in range(rows_number)]def SI(): return sys.stdin.readline().rstrip()dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]inf = 18446744073709551615# inf = 4294967295# md = 10**9+7md = 998244353n = II()to = [[] for _ in range(n)]for _ in range(n-1):u, v = LI1()to[u].append(v)to[v].append(u)dp = [0]*nst = [0]base = 0par = [-1]*nwhile st:u = st.pop()for v in to[u]:if v == par[u]: continuepar[v] = uif u < v:dp[v] = dp[u]+1else:dp[v] = dp[u]-1base += 1st.append(v)for c in dp:print(c+base)