Submission #63058140


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),3+int(prev==-1))):
        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 808 Byte
Status WA
Exec Time 430 ms
Memory 191244 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 3
AC × 49
WA × 10
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 76608 KB
hand01.txt AC 56 ms 76664 KB
hand02.txt AC 57 ms 76716 KB
hand03.txt AC 57 ms 76920 KB
sample00.txt AC 57 ms 76572 KB
sample01.txt AC 58 ms 76660 KB
sample02.txt AC 58 ms 76412 KB
testcase00.txt AC 56 ms 76696 KB
testcase01.txt AC 57 ms 76460 KB
testcase02.txt AC 57 ms 76968 KB
testcase03.txt AC 57 ms 76596 KB
testcase04.txt AC 269 ms 110388 KB
testcase05.txt AC 275 ms 112516 KB
testcase06.txt AC 156 ms 95384 KB
testcase07.txt AC 278 ms 112204 KB
testcase08.txt AC 154 ms 93888 KB
testcase09.txt AC 259 ms 112972 KB
testcase10.txt AC 247 ms 121964 KB
testcase11.txt AC 430 ms 191244 KB
testcase12.txt AC 173 ms 99540 KB
testcase13.txt AC 266 ms 112692 KB
testcase14.txt AC 211 ms 107144 KB
testcase15.txt AC 264 ms 112496 KB
testcase16.txt AC 232 ms 110812 KB
testcase17.txt AC 246 ms 112440 KB
testcase18.txt AC 256 ms 112844 KB
testcase19.txt AC 253 ms 112596 KB
testcase20.txt AC 191 ms 99872 KB
testcase21.txt AC 292 ms 112860 KB
testcase22.txt AC 163 ms 97892 KB
testcase23.txt AC 207 ms 105272 KB
testcase24.txt AC 214 ms 102736 KB
testcase25.txt AC 215 ms 105244 KB
testcase26.txt AC 141 ms 94576 KB
testcase27.txt AC 231 ms 104876 KB
testcase28.txt AC 193 ms 103096 KB
testcase29.txt AC 206 ms 105064 KB
testcase30.txt AC 185 ms 102084 KB
testcase31.txt AC 208 ms 104832 KB
testcase32.txt AC 187 ms 97540 KB
testcase33.txt AC 235 ms 109036 KB
testcase34.txt WA 128 ms 88824 KB
testcase35.txt AC 248 ms 109592 KB
testcase36.txt WA 177 ms 96532 KB
testcase37.txt AC 277 ms 109348 KB
testcase38.txt AC 200 ms 98952 KB
testcase39.txt WA 300 ms 109912 KB
testcase40.txt AC 218 ms 104636 KB
testcase41.txt AC 291 ms 109452 KB
testcase42.txt WA 181 ms 94796 KB
testcase43.txt WA 261 ms 109376 KB
testcase44.txt WA 228 ms 104908 KB
testcase45.txt WA 251 ms 108812 KB
testcase46.txt WA 156 ms 93816 KB
testcase47.txt AC 247 ms 109180 KB
testcase48.txt WA 149 ms 91176 KB
testcase49.txt AC 259 ms 108908 KB
testcase50.txt AC 242 ms 107348 KB
testcase51.txt WA 235 ms 108944 KB


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