Submission #63055405


Source Code Expand

Copy
n=int(input())
g=[[]for _ in range(n)]
for _ in range(n-1):
a,b=map(lambda x:int(x)-1,input().split())
g[a].append(b)
g[b].append(a)
import pypyjit
pypyjit.set_param('max_unroll_recursion=-1')
start=-1
for i in range(n):
if len(g[i])>=4:
start=i;break
if start==-1:
exit(print(start))
import sys
sys.setrecursionlimit(10**6)
visited=set()
def dfs(now,prev=-1):
cnt=[]
visited.add(now)
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
n=int(input())
g=[[]for _ in range(n)]
for _ in range(n-1):
    a,b=map(lambda x:int(x)-1,input().split())
    g[a].append(b)
    g[b].append(a)
import pypyjit
pypyjit.set_param('max_unroll_recursion=-1')

start=-1
for i in range(n):
    if len(g[i])>=4:
        start=i;break
if start==-1:
    exit(print(start))
import sys
sys.setrecursionlimit(10**6)
visited=set()
def dfs(now,prev=-1):
    cnt=[]
    visited.add(now)
    for v in g[now]:
        if len(g[v])<4:continue
        if v==prev:continue
        cnt.append(dfs(v,now))
    res=1
    cnt.sort(reverse=True)
    for i in range(min(len(cnt),4)):
        res+=cnt[i]
    return res
m=1
for start in range(n):
    if len(g[start])>=4 and start not in visited:
        m=max(m,dfs(start))
print(3*m+2)

Submission Info

Submission Time
Task F - Alkane
User juten
Language Python (PyPy 3.10-v7.3.12)
Score 0
Code Size 794 Byte
Status WA
Exec Time 435 ms
Memory 187072 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 3
AC × 39
WA × 20
Set Name Test Cases
Sample sample00.txt, sample01.txt, sample02.txt
All hand00.txt, hand01.txt, hand02.txt, hand03.txt, sample00.txt, sample01.txt, sample02.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt, testcase19.txt, testcase20.txt, testcase21.txt, testcase22.txt, testcase23.txt, testcase24.txt, testcase25.txt, testcase26.txt, testcase27.txt, testcase28.txt, testcase29.txt, testcase30.txt, testcase31.txt, testcase32.txt, testcase33.txt, testcase34.txt, testcase35.txt, testcase36.txt, testcase37.txt, testcase38.txt, testcase39.txt, testcase40.txt, testcase41.txt, testcase42.txt, testcase43.txt, testcase44.txt, testcase45.txt, testcase46.txt, testcase47.txt, testcase48.txt, testcase49.txt, testcase50.txt, testcase51.txt
Case Name Status Exec Time Memory
hand00.txt AC 55 ms 76460 KB
hand01.txt AC 56 ms 76792 KB
hand02.txt AC 55 ms 76492 KB
hand03.txt AC 54 ms 76572 KB
sample00.txt AC 55 ms 76828 KB
sample01.txt AC 55 ms 76692 KB
sample02.txt AC 55 ms 76720 KB
testcase00.txt AC 54 ms 76724 KB
testcase01.txt AC 57 ms 76500 KB
testcase02.txt AC 58 ms 76660 KB
testcase03.txt AC 55 ms 76612 KB
testcase04.txt AC 234 ms 110556 KB
testcase05.txt AC 260 ms 112108 KB
testcase06.txt AC 156 ms 95116 KB
testcase07.txt AC 269 ms 111804 KB
testcase08.txt AC 139 ms 94312 KB
testcase09.txt AC 250 ms 113000 KB
testcase10.txt AC 246 ms 121712 KB
testcase11.txt AC 435 ms 187072 KB
testcase12.txt AC 171 ms 99248 KB
testcase13.txt AC 259 ms 113000 KB
testcase14.txt AC 229 ms 107152 KB
testcase15.txt AC 256 ms 112968 KB
testcase16.txt AC 235 ms 110012 KB
testcase17.txt AC 302 ms 112848 KB
testcase18.txt AC 249 ms 112580 KB
testcase19.txt AC 277 ms 112024 KB
testcase20.txt AC 176 ms 99104 KB
testcase21.txt AC 292 ms 112064 KB
testcase22.txt AC 171 ms 97936 KB
testcase23.txt AC 226 ms 105332 KB
testcase24.txt AC 218 ms 102700 KB
testcase25.txt AC 218 ms 104992 KB
testcase26.txt AC 145 ms 94520 KB
testcase27.txt AC 232 ms 105260 KB
testcase28.txt AC 208 ms 102980 KB
testcase29.txt AC 237 ms 105196 KB
testcase30.txt AC 187 ms 102060 KB
testcase31.txt AC 203 ms 105048 KB
testcase32.txt WA 165 ms 97528 KB
testcase33.txt WA 271 ms 109084 KB
testcase34.txt WA 132 ms 89184 KB
testcase35.txt WA 238 ms 109168 KB
testcase36.txt WA 163 ms 96344 KB
testcase37.txt WA 240 ms 109444 KB
testcase38.txt WA 196 ms 98396 KB
testcase39.txt WA 277 ms 109504 KB
testcase40.txt WA 213 ms 104376 KB
testcase41.txt WA 277 ms 109508 KB
testcase42.txt WA 159 ms 94696 KB
testcase43.txt WA 234 ms 108836 KB
testcase44.txt WA 202 ms 104400 KB
testcase45.txt WA 246 ms 108980 KB
testcase46.txt WA 141 ms 93664 KB
testcase47.txt WA 244 ms 109080 KB
testcase48.txt WA 151 ms 90864 KB
testcase49.txt WA 301 ms 109144 KB
testcase50.txt WA 228 ms 107292 KB
testcase51.txt WA 235 ms 108904 KB


2025-05-05 (Mon)
15:13:09 +09:00