結果

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

ソースコード

diff #
raw source code

import sys
sys.setrecursionlimit(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