結果
問題 | No.1817 Reversed Edges |
ユーザー |
|
提出日時 | 2022-01-21 21:54:53 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 396 ms / 2,000 ms |
コード長 | 1,501 bytes |
コンパイル時間 | 284 ms |
コンパイル使用メモリ | 82,492 KB |
実行使用メモリ | 119,808 KB |
最終ジャッジ日時 | 2024-11-25 23:46:40 |
合計ジャッジ時間 | 8,088 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 23 |
ソースコード
# import sys# input = sys.stdin.readlinedef mp():return map(int,input().split())def lmp():return list(map(int,input().split()))def mps(A):return [tuple(map(int, input().split())) for _ in range(A)]def stoi(LIST):return list(map(int,LIST))def itos(LIST):return list(map(str,LIST))def bitA(X,A):return X & 1<<A == 1<<Aimport mathimport bisectimport heapqimport timefrom copy import copy as ccfrom copy import deepcopy as dcfrom itertools import accumulate, productfrom collections import Counter, defaultdict, dequedef ceil(U,V):return (U+V-1)//Vdef modf1(N,MOD):return (N-1)%MOD+1inf = int(1e18+20)mod = int(1e9+7)n = int(input())edge = [[] for i in range(n)]for i in range(n-1):a,b = mp()a -= 1b -= 1edge[a].append(b)edge[b].append(a)ans = [0]*nq = deque([0])used = set()used.add(0)base = 0while q:here = q.popleft()for i in edge[here]:if i not in used:q.append(i)used.add(i)if i < here:base += 1ans[0] = baseq = deque([0])used = set()used.add(0)while q:here = q.popleft()for i in edge[here]:if i not in used:q.append(i)used.add(i)if i > here:ans[i] = ans[here] + 1else:ans[i] = ans[here] - 1for i in ans:print(i)# n = int(input())# a = lmp()# a.sort(reverse=True)# ans = a[0]# for i in range(1,n):# if i % 2 == 1:# ans *= a[i]# else:# ans = ceil(ans, a[i])# print(ans)