Submission #63059538


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)
def dfs(now,prev=-1):
cnt=[]
for v in g[now]:
if len(g[v])<4:continue
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
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)
def dfs(now,prev=-1):
    cnt=[]
    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),3+int(prev==-1))):
        res+=cnt[i]
    return res
m=1
for start in range(n):
    if len(g[start])>=4:
        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 746 Byte
Status TLE
Exec Time 2230 ms
Memory 405552 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 3
AC × 21
TLE × 38
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 56 ms 76796 KB
hand01.txt AC 56 ms 76688 KB
hand02.txt AC 56 ms 76616 KB
hand03.txt AC 56 ms 76616 KB
sample00.txt AC 56 ms 76544 KB
sample01.txt AC 56 ms 76616 KB
sample02.txt AC 57 ms 76484 KB
testcase00.txt AC 56 ms 76424 KB
testcase01.txt AC 58 ms 76828 KB
testcase02.txt AC 57 ms 76756 KB
testcase03.txt AC 56 ms 76920 KB
testcase04.txt TLE 2213 ms 106272 KB
testcase05.txt TLE 2213 ms 107692 KB
testcase06.txt TLE 2212 ms 96544 KB
testcase07.txt TLE 2213 ms 107744 KB
testcase08.txt TLE 2212 ms 95668 KB
testcase09.txt TLE 2213 ms 107944 KB
testcase10.txt TLE 2228 ms 361356 KB
testcase11.txt TLE 2230 ms 405552 KB
testcase12.txt TLE 2212 ms 98632 KB
testcase13.txt TLE 2213 ms 108288 KB
testcase14.txt TLE 2213 ms 104072 KB
testcase15.txt TLE 2213 ms 107892 KB
testcase16.txt TLE 2213 ms 106592 KB
testcase17.txt TLE 2213 ms 107880 KB
testcase18.txt TLE 2213 ms 108116 KB
testcase19.txt TLE 2213 ms 107416 KB
testcase20.txt TLE 2212 ms 99616 KB
testcase21.txt TLE 2213 ms 108184 KB
testcase22.txt AC 181 ms 98016 KB
testcase23.txt AC 246 ms 105452 KB
testcase24.txt AC 236 ms 102836 KB
testcase25.txt AC 222 ms 105108 KB
testcase26.txt AC 144 ms 94448 KB
testcase27.txt AC 241 ms 105060 KB
testcase28.txt AC 234 ms 102960 KB
testcase29.txt AC 240 ms 104816 KB
testcase30.txt AC 213 ms 102312 KB
testcase31.txt AC 230 ms 104692 KB
testcase32.txt TLE 2212 ms 99088 KB
testcase33.txt TLE 2213 ms 108888 KB
testcase34.txt TLE 2212 ms 91752 KB
testcase35.txt TLE 2213 ms 109516 KB
testcase36.txt TLE 2212 ms 98392 KB
testcase37.txt TLE 2213 ms 109472 KB
testcase38.txt TLE 2212 ms 100988 KB
testcase39.txt TLE 2213 ms 109340 KB
testcase40.txt TLE 2213 ms 104952 KB
testcase41.txt TLE 2213 ms 109512 KB
testcase42.txt TLE 2212 ms 96424 KB
testcase43.txt TLE 2213 ms 109364 KB
testcase44.txt TLE 2213 ms 105304 KB
testcase45.txt TLE 2213 ms 109356 KB
testcase46.txt TLE 2212 ms 96164 KB
testcase47.txt TLE 2213 ms 109636 KB
testcase48.txt TLE 2212 ms 93396 KB
testcase49.txt TLE 2213 ms 109336 KB
testcase50.txt TLE 2213 ms 108076 KB
testcase51.txt TLE 2213 ms 109096 KB


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