Submission #63050358


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')
for i in range(n):
g[i].sort(key=lambda x:len(g[x]),reverse=True)
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):
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
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')

for i in range(n):
    g[i].sort(key=lambda x:len(g[x]),reverse=True)
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=1
    visited.add(now)
    for v in g[now]:
        if len(g[v])<4:break
        if v==prev:continue
        cnt+=dfs(v,now)
    return cnt
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 757 Byte
Status WA
Exec Time 712 ms
Memory 171244 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 58 ms 76608 KB
hand01.txt AC 59 ms 76768 KB
hand02.txt AC 58 ms 76540 KB
hand03.txt AC 60 ms 76716 KB
sample00.txt AC 58 ms 76472 KB
sample01.txt AC 60 ms 76676 KB
sample02.txt AC 59 ms 76412 KB
testcase00.txt AC 61 ms 76772 KB
testcase01.txt AC 59 ms 76604 KB
testcase02.txt AC 60 ms 76980 KB
testcase03.txt AC 60 ms 76436 KB
testcase04.txt AC 551 ms 120284 KB
testcase05.txt AC 601 ms 123920 KB
testcase06.txt AC 255 ms 98716 KB
testcase07.txt AC 606 ms 123012 KB
testcase08.txt AC 253 ms 98380 KB
testcase09.txt AC 595 ms 123408 KB
testcase10.txt AC 327 ms 119784 KB
testcase11.txt AC 712 ms 171244 KB
testcase12.txt AC 332 ms 105124 KB
testcase13.txt AC 603 ms 123420 KB
testcase14.txt AC 489 ms 115716 KB
testcase15.txt AC 596 ms 123876 KB
testcase16.txt AC 558 ms 121952 KB
testcase17.txt AC 604 ms 123320 KB
testcase18.txt AC 591 ms 123224 KB
testcase19.txt AC 587 ms 123696 KB
testcase20.txt AC 359 ms 107580 KB
testcase21.txt AC 589 ms 123436 KB
testcase22.txt AC 351 ms 105472 KB
testcase23.txt AC 516 ms 115856 KB
testcase24.txt AC 521 ms 115044 KB
testcase25.txt AC 550 ms 116364 KB
testcase26.txt AC 311 ms 101452 KB
testcase27.txt AC 535 ms 116020 KB
testcase28.txt AC 515 ms 113800 KB
testcase29.txt AC 532 ms 116620 KB
testcase30.txt AC 475 ms 111888 KB
testcase31.txt AC 535 ms 116552 KB
testcase32.txt WA 326 ms 102972 KB
testcase33.txt WA 575 ms 120096 KB
testcase34.txt WA 179 ms 91068 KB
testcase35.txt WA 576 ms 119772 KB
testcase36.txt WA 312 ms 101352 KB
testcase37.txt WA 579 ms 120436 KB
testcase38.txt WA 369 ms 105708 KB
testcase39.txt WA 579 ms 120144 KB
testcase40.txt WA 491 ms 114116 KB
testcase41.txt WA 583 ms 119892 KB
testcase42.txt WA 281 ms 99348 KB
testcase43.txt WA 576 ms 120508 KB
testcase44.txt WA 485 ms 114128 KB
testcase45.txt WA 579 ms 119816 KB
testcase46.txt WA 282 ms 98564 KB
testcase47.txt WA 569 ms 120164 KB
testcase48.txt WA 213 ms 94460 KB
testcase49.txt WA 572 ms 120580 KB
testcase50.txt WA 565 ms 117780 KB
testcase51.txt WA 565 ms 119916 KB


2025-05-05 (Mon)
15:12:56 +09:00