結果
問題 | No.1718 Random Squirrel |
ユーザー | puzneko |
提出日時 | 2021-11-15 23:47:04 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,716 bytes |
コンパイル時間 | 522 ms |
コンパイル使用メモリ | 82,256 KB |
実行使用メモリ | 137,096 KB |
最終ジャッジ日時 | 2024-12-15 08:26:20 |
合計ジャッジ時間 | 8,832 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
53,816 KB |
testcase_01 | AC | 35 ms
53,148 KB |
testcase_02 | AC | 34 ms
53,088 KB |
testcase_03 | AC | 34 ms
53,608 KB |
testcase_04 | AC | 36 ms
53,488 KB |
testcase_05 | AC | 35 ms
53,820 KB |
testcase_06 | AC | 35 ms
53,140 KB |
testcase_07 | WA | - |
testcase_08 | AC | 37 ms
53,076 KB |
testcase_09 | AC | 39 ms
54,376 KB |
testcase_10 | AC | 36 ms
52,920 KB |
testcase_11 | WA | - |
testcase_12 | AC | 158 ms
84,420 KB |
testcase_13 | AC | 246 ms
100,012 KB |
testcase_14 | WA | - |
testcase_15 | AC | 266 ms
111,488 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 332 ms
123,980 KB |
testcase_19 | AC | 286 ms
111,560 KB |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 415 ms
135,324 KB |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 423 ms
135,212 KB |
testcase_26 | AC | 239 ms
137,096 KB |
testcase_27 | AC | 231 ms
118,640 KB |
testcase_28 | AC | 223 ms
134,920 KB |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | AC | 215 ms
116,584 KB |
testcase_32 | WA | - |
ソースコード
from sys import stdin n, m, *indata = map(int, stdin.read().split()) offset = 0 g = [[] for i in range(n+1)] for i in range(n-1): s, t = indata[offset + 2*i],indata[offset + 2*i+1] g[s].append((t,i)) g[t].append((s,i)) offset += (n-1)*2 d = [False for i in range(n+1)] for i in range(m): d[indata[offset + i]] = True que = [(1,0)] dp = [-1 for i in range(n+1)] dpdist = [-1 for i in range(n+1)] check = [0 for i in range(n+1)] while que: now, inout = que.pop() if inout == 0: check[now] = 1 que.append((now,1)) for i, ind in g[now]: if check[i] == 0: que.append((i,0)) else: kari = -1 distmax = -1 check[now] = 2 for i, ind in g[now]: if check[i] == 2: if dp[i] != -1: kari += dp[i] + 2 distmax = max(distmax,dpdist[i]) if kari != -1: kari += 1 distmax += 1 else: if d[now]: kari = 0 distmax = max(distmax,0) dp[now] = kari dpdist[now] = distmax dp2 = [-1 for i in range(n+1)] dpdist2 = [-1 for i in range(n+1)] que = [(1,-1)] check = [False for i in range(n+1)] while que: now, come = que.pop() check[now] = True ruiseki = [0] ruisekidist = [-1] for i, ind in g[now]: kari = ruiseki[-1] distmax = ruisekidist[-1] if ind != come: if dp[i] != -1: kari = kari + dp[i] + 2 distmax = max(distmax,dpdist[i]) else: if dp2[ind] != -1: kari = kari + dp2[ind] + 2 distmax = max(distmax,dpdist2[ind]) ruiseki.append(kari) ruisekidist.append(distmax) ruiseki2 = [0] ruisekidist2 = [-1] for i, ind in reversed(g[now]): kari = ruiseki2[-1] distmax = ruisekidist2[-1] if ind != come: if dp[i] != -1: kari = kari + dp[i] + 2 distmax = max(distmax,dpdist[i]) else: if dp2[ind] != -1: kari = kari + dp2[ind] + 2 distmax = max(distmax,dpdist2[ind]) ruiseki2.append(kari) ruisekidist2.append(distmax) dp[now] = ruiseki[-1] dpdist[now] = ruisekidist[-1] + 1 val = 0 for i, ind in g[now]: kari = ruiseki[val] + ruiseki2[-2-val] distmax = max(ruisekidist[val], ruisekidist2[-2-val]) dp2[ind] = kari dpdist2[ind] = distmax + 1 val += 1 for i, ind in g[now]: if not check[i]: que.append((i, ind)) for i in range(1,n+1): ans = dp[i] - dpdist[i] print("{}".format(ans))