結果
問題 | No.1817 Reversed Edges |
ユーザー |
![]() |
提出日時 | 2022-01-21 21:54:58 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,090 bytes |
コンパイル時間 | 92 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 34,432 KB |
最終ジャッジ日時 | 2024-05-04 12:44:32 |
合計ジャッジ時間 | 9,211 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 32 ms
10,752 KB |
testcase_01 | AC | 28 ms
10,880 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | AC | 27 ms
10,752 KB |
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 | - |
testcase_22 | AC | 367 ms
29,112 KB |
testcase_23 | AC | 384 ms
29,140 KB |
testcase_24 | AC | 391 ms
34,432 KB |
ソースコード
import sys #input = sys.stdin.readline #文字列につけてはダメ #input = sys.stdin.buffer.readline #文字列につけてはダメ #sys.setrecursionlimit(1000000) #import bisect #import itertools #import random from heapq import heapify, heappop, heappush #from collections import defaultdict #from collections import deque #import copy #import math #from functools import lru_cache #@lru_cache(maxsize=None) #MOD = pow(10,9) + 7 #MOD = 998244353 #dx = [1,0,-1,0] #dy = [0,1,0,-1] def main(): N = int(input()) G = [[] for _ in range(N)] for i in range(N-1): a,b = map(int,input().split()) a -= 1; b -= 1 G[a].append(b) G[b].append(a) ans = [-1]*N ans[0] = 0 par = [-1]*N stack = [0] while stack: v = stack.pop() for u in G[v]: if par[v] == u: continue par[u] = v if u > v: ans[u] = ans[v] + 1 else: ans[u] = ans[v] - 1 stack.append(u) print(*ans,sep="\n") if __name__ == '__main__': main()