結果

問題 No.1817 Reversed Edges
ユーザー ygd.ygd.
提出日時 2022-01-21 22:01:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,297 bytes
コンパイル時間 190 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 34,432 KB
最終ジャッジ日時 2024-05-04 12:56:41
合計ジャッジ時間 10,481 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
10,752 KB
testcase_01 AC 32 ms
10,880 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 32 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 420 ms
29,136 KB
testcase_23 AC 421 ms
29,236 KB
testcase_24 AC 437 ms
34,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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
    start = 0
    stack = [0]
    par = [-1]*N
    while stack:
        v = stack.pop()
        for u in G[v]:
            if par[v] == u: continue
            par[u] = v
            if u < v:
                start += 1
    ans[0] = start
    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()
0