Submission #65916265


Source Code Expand

Copy
import sys
sys.setrecursionlimit(10**6)
n=int(input())
g=[[]for _ in range(n)]
edges=[0]*n
for i in range(1,n):
u,v=map(int,input().split())
u-=1
v-=1
g[u].append(v)
g[v].append(u)
edges[i]=(u,v)
tin=[0]*n
tout=[0]*n
parent=[0]*n
timer=0
def dfs(u,p):
global timer
tin[u]=timer
timer+=1
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
import sys
sys.setrecursionlimit(10**6)
n=int(input())
g=[[]for _ in range(n)]
edges=[0]*n
for i in range(1,n):
    u,v=map(int,input().split())
    u-=1
    v-=1
    g[u].append(v)
    g[v].append(u)
    edges[i]=(u,v)

tin=[0]*n
tout=[0]*n
parent=[0]*n
timer=0
def dfs(u,p):
    global timer
    tin[u]=timer
    timer+=1
    parent[u]=p
    for v in g[u]:
        if v==p:continue
        dfs(v,u)
    tout[u]=timer-1
dfs(0,-1)
child=[0]*n
for i in range(1,n):
    u,v=edges[i]
    child[i]=u if parent[u]==v else v

from atcoder.fenwicktree import FenwickTree
ft=FenwickTree(n)
for i in range(n):
    ft.add(tin[i],1)
for _ in range(int(input())):
    q=list(map(int,input().split()))
    if q[0]==1:
        x=q[1]-1
        w=q[2]
        ft.add(tin[x],w)
    else:
        y=q[1]
        v=child[y]
        s=ft.sum(tin[v],tout[v]+1)
        ans=abs(ft.sum(0,n)-2*s)
        print(ans)

Submission Info

Submission Time
Task F - Compare Tree Weights
User juten
Language Python (PyPy 3.10-v7.3.12)
Score 0
Code Size 939 Byte
Status TLE
Exec Time 2320 ms
Memory 2154780 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 1
AC × 39
TLE × 4
Set Name Test Cases
Sample example_00.txt
All example_00.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt
Case Name Status Exec Time Memory
example_00.txt AC 119 ms 84512 KB
hand_00.txt AC 1210 ms 408948 KB
hand_01.txt AC 860 ms 160708 KB
hand_02.txt AC 966 ms 147808 KB
hand_03.txt AC 732 ms 147984 KB
hand_04.txt AC 1176 ms 148260 KB
hand_05.txt AC 1147 ms 147476 KB
hand_06.txt AC 118 ms 84220 KB
hand_07.txt TLE 2320 ms 2154780 KB
hand_08.txt AC 967 ms 145656 KB
hand_09.txt AC 993 ms 145668 KB
hand_10.txt AC 941 ms 148848 KB
hand_11.txt AC 908 ms 153724 KB
random_00.txt AC 1254 ms 389720 KB
random_01.txt AC 1486 ms 486384 KB
random_02.txt TLE 2147 ms 977692 KB
random_03.txt TLE 2311 ms 1958156 KB
random_04.txt TLE 2313 ms 2007000 KB
random_05.txt AC 965 ms 157032 KB
random_06.txt AC 969 ms 157676 KB
random_07.txt AC 921 ms 156780 KB
random_08.txt AC 940 ms 157400 KB
random_09.txt AC 868 ms 157556 KB
random_10.txt AC 950 ms 150232 KB
random_11.txt AC 943 ms 148116 KB
random_12.txt AC 947 ms 147736 KB
random_13.txt AC 946 ms 149396 KB
random_14.txt AC 956 ms 147184 KB
random_15.txt AC 979 ms 148656 KB
random_16.txt AC 1008 ms 149648 KB
random_17.txt AC 998 ms 150360 KB
random_18.txt AC 997 ms 147376 KB
random_19.txt AC 977 ms 148112 KB
random_20.txt AC 992 ms 149916 KB
random_21.txt AC 1001 ms 149552 KB
random_22.txt AC 960 ms 150000 KB
random_23.txt AC 954 ms 149056 KB
random_24.txt AC 959 ms 147840 KB
random_25.txt AC 946 ms 147896 KB
random_26.txt AC 972 ms 149396 KB
random_27.txt AC 965 ms 148808 KB
random_28.txt AC 972 ms 148808 KB
random_29.txt AC 981 ms 148852 KB


2025-05-17 (Sat)
22:43:43 +09:00