結果

問題 No.2427 Tree Distance Two
ユーザー mono_0812mono_0812
提出日時 2023-08-18 21:39:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 731 ms / 2,000 ms
コード長 3,222 bytes
コンパイル時間 662 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 144,512 KB
最終ジャッジ日時 2024-11-28 06:13:06
合計ジャッジ時間 16,039 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
93,056 KB
testcase_01 AC 140 ms
92,928 KB
testcase_02 AC 138 ms
93,056 KB
testcase_03 AC 731 ms
127,488 KB
testcase_04 AC 140 ms
92,928 KB
testcase_05 AC 731 ms
127,488 KB
testcase_06 AC 136 ms
92,544 KB
testcase_07 AC 619 ms
144,512 KB
testcase_08 AC 661 ms
142,592 KB
testcase_09 AC 596 ms
142,592 KB
testcase_10 AC 635 ms
143,616 KB
testcase_11 AC 664 ms
141,824 KB
testcase_12 AC 662 ms
139,392 KB
testcase_13 AC 687 ms
135,552 KB
testcase_14 AC 397 ms
125,952 KB
testcase_15 AC 136 ms
93,056 KB
testcase_16 AC 143 ms
93,056 KB
testcase_17 AC 145 ms
92,416 KB
testcase_18 AC 140 ms
92,544 KB
testcase_19 AC 140 ms
93,056 KB
testcase_20 AC 186 ms
94,080 KB
testcase_21 AC 193 ms
94,080 KB
testcase_22 AC 174 ms
93,952 KB
testcase_23 AC 176 ms
93,568 KB
testcase_24 AC 190 ms
94,080 KB
testcase_25 AC 285 ms
101,504 KB
testcase_26 AC 480 ms
114,304 KB
testcase_27 AC 377 ms
107,648 KB
testcase_28 AC 681 ms
124,672 KB
testcase_29 AC 639 ms
120,832 KB
testcase_30 AC 515 ms
113,280 KB
testcase_31 AC 365 ms
105,984 KB
testcase_32 AC 495 ms
113,152 KB
testcase_33 AC 479 ms
110,460 KB
testcase_34 AC 288 ms
98,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

############################################################################################
import bisect,collections,copy,heapq,itertools,math,string,sys,queue,time,random
from decimal import Decimal
def I(): return input()
def IS(): return input().split()
def II(): return int(input())
def IIS(): return list(map(int,input().split()))
def LIIS(): return list(map(int,input().split()))

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

import math

def prime_numbers(n):
    prime = [True for i in range(n+1)]
    prime[0] = False
    prime[1] = False

    sqrt_n = math.ceil(math.sqrt(n))
    for i in range(2, sqrt_n):
        if prime[i]:
            for j in range(2*i, n+1, i):
                prime[j] = False
    numbers=[]
    for i in range(2,n+1):
        if prime[i]:
            numbers.append(i)

    return numbers

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
 
    if temp!=1:
        arr.append([temp, 1])
 
    if arr==[] and n>1:
        arr.append([n, 1])
 
    return arr
from collections import defaultdict


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        group_members = defaultdict(list)
        for member in range(self.n):
            group_members[self.find(member)].append(member)
        return group_members

    def __str__(self):
        return '\n'.join(f'{r}: {m}' for r, m in self.all_group_members().items())
 
INF=10**18
MOD=998244353
MOD2=10**9+7
sys.setrecursionlimit(500005)
def bit_count(x):
    return bin(x).count("1")
def yesno(f):
    if f:print("Yes")
    else:print("No")
dxy=((1,0),(0,-1),(-1,0),(0,1))
##################################################################
n=II()
path=[[] for i in range(n)]
for i in range(n-1):
    u,v=IIS()
    path[u-1].append(v-1)
    path[v-1].append(u-1)

for i in range(n):
    res=0
    for j in path[i]:
        res+=len(path[j])-1
    print(res)
0