結果

問題 No.3373 Partial Complement Tree
コンテスト
ユーザー titia
提出日時 2025-11-21 22:27:48
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 815 bytes
コンパイル時間 187 ms
コンパイル使用メモリ 82,216 KB
実行使用メモリ 101,224 KB
最終ジャッジ日時 2025-11-21 22:28:06
合計ジャッジ時間 14,574 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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)

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

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

        for x in L:
            USE[x]=-1

    print(ANS//2)
                
                

    
    

    
0