結果

問題 No.3373 Partial Complement Tree
コンテスト
ユーザー titia
提出日時 2025-11-21 22:25:48
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 897 bytes
コンパイル時間 307 ms
コンパイル使用メモリ 82,504 KB
実行使用メモリ 100,056 KB
最終ジャッジ日時 2025-11-21 22:26:08
合計ジャッジ時間 18,902 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 19 TLE * 1 -- * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

mod=998244353

T=int(input())

for tests in range(T):
    N=int(input())

    E=[[] for i in range(N)]

    for i in range(N-1):
        x,y=map(int,input().split())
        x-=1
        y-=1
        E[x].append(y)
        E[y].append(x)

    DICT=dict()
    ANS=0
    for i in range(N):
        Q=[i]
        DICT[i]=0
        L=[]
        while Q:
            x=Q.pop()
            L.append(x)
            for to in E[x]:
                if to in DICT:
                    continue
                DICT[to]=DICT[x]+1

                if DICT[to]==3:
                    L.append(to)
                    ANS+=1
                else:
                    Q.append(to)

        #print(L,DICT)

        for x in L:
            if x in DICT:
                del DICT[x]

        #print(DICT)

    print(ANS//2)
                
                

    
    

    
0