結果

問題 No.3852 Partition into 2-edge paths
コンテスト
ユーザー Kurao
提出日時 2026-11-02 22:54:15
言語 PyPy3
(8.0.1 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 700 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 82 ms
コンパイル使用メモリ 64,480 KB
実行使用メモリ 454,604 KB
最終ジャッジ日時 2026-12-04 20:52:26
合計ジャッジ時間 22,125 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge6_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24 TLE * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
sys.setrecursionlimit(2*10**7)

n=int(input())
v={i:[] for i in range(2*n+1)}
for _ in range(2*n):
    i,j=map(int,input().split())
    i-=1
    j-=1
    v[i].append(j)
    v[j].append(i)

childs=[1]*(2*n+1)
vis=set()
def calc_childs(i):
    vis.add(i)
    for j in v[i]:
        if j not in vis:
            calc_childs(j)
            childs[i]+=childs[j]
    
calc_childs(0)

ans=1
vis=set()
def dfs(i):
    global ans
    vis.add(i)
    cnt=0
    for j in v[i]:
        if j not in vis:
            dfs(j)
            if childs[j]%2==1:
                cnt+=1
    if cnt%2==0:
        cnt-=1
    while cnt>1:
        ans*=cnt
        ans%=998244353
        cnt-=2
dfs(0)
print(ans)
    
0