結果
| 問題 | No.1817 Reversed Edges |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-01-21 21:54:53 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 272 ms / 2,000 ms |
| コード長 | 1,501 bytes |
| 記録 | |
| コンパイル時間 | 405 ms |
| コンパイル使用メモリ | 84,864 KB |
| 実行使用メモリ | 125,424 KB |
| 最終ジャッジ日時 | 2026-05-20 12:51:00 |
| 合計ジャッジ時間 | 6,542 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 23 |
ソースコード
# import sys
# input = sys.stdin.readline
def 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<<A
import math
import bisect
import heapq
import time
from copy import copy as cc
from copy import deepcopy as dc
from itertools import accumulate, product
from collections import Counter, defaultdict, deque
def ceil(U,V):return (U+V-1)//V
def modf1(N,MOD):return (N-1)%MOD+1
inf = 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 -= 1
b -= 1
edge[a].append(b)
edge[b].append(a)
ans = [0]*n
q = deque([0])
used = set()
used.add(0)
base = 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:base += 1
ans[0] = base
q = 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] + 1
else:ans[i] = ans[here] - 1
for 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)