結果
問題 | No.2325 Skill Tree |
ユーザー | googol_S0 |
提出日時 | 2023-05-28 14:13:28 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,107 ms / 3,000 ms |
コード長 | 2,490 bytes |
コンパイル時間 | 286 ms |
コンパイル使用メモリ | 82,160 KB |
実行使用メモリ | 159,764 KB |
最終ジャッジ日時 | 2024-06-08 04:57:59 |
合計ジャッジ時間 | 34,014 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
52,736 KB |
testcase_01 | AC | 41 ms
52,864 KB |
testcase_02 | AC | 40 ms
52,736 KB |
testcase_03 | AC | 39 ms
52,992 KB |
testcase_04 | AC | 39 ms
52,864 KB |
testcase_05 | AC | 39 ms
52,224 KB |
testcase_06 | AC | 40 ms
52,480 KB |
testcase_07 | AC | 478 ms
88,476 KB |
testcase_08 | AC | 545 ms
112,472 KB |
testcase_09 | AC | 554 ms
98,560 KB |
testcase_10 | AC | 605 ms
130,796 KB |
testcase_11 | AC | 667 ms
114,396 KB |
testcase_12 | AC | 979 ms
157,472 KB |
testcase_13 | AC | 1,011 ms
157,592 KB |
testcase_14 | AC | 1,047 ms
158,244 KB |
testcase_15 | AC | 1,005 ms
157,600 KB |
testcase_16 | AC | 1,081 ms
156,960 KB |
testcase_17 | AC | 987 ms
157,852 KB |
testcase_18 | AC | 942 ms
156,960 KB |
testcase_19 | AC | 1,001 ms
157,600 KB |
testcase_20 | AC | 965 ms
157,088 KB |
testcase_21 | AC | 969 ms
157,088 KB |
testcase_22 | AC | 1,031 ms
156,960 KB |
testcase_23 | AC | 1,107 ms
157,472 KB |
testcase_24 | AC | 1,075 ms
157,344 KB |
testcase_25 | AC | 1,083 ms
156,828 KB |
testcase_26 | AC | 1,051 ms
156,704 KB |
testcase_27 | AC | 954 ms
159,128 KB |
testcase_28 | AC | 931 ms
159,260 KB |
testcase_29 | AC | 915 ms
159,244 KB |
testcase_30 | AC | 949 ms
158,868 KB |
testcase_31 | AC | 917 ms
158,868 KB |
testcase_32 | AC | 882 ms
158,744 KB |
testcase_33 | AC | 889 ms
158,744 KB |
testcase_34 | AC | 883 ms
158,620 KB |
testcase_35 | AC | 924 ms
159,764 KB |
testcase_36 | AC | 940 ms
159,640 KB |
testcase_37 | AC | 936 ms
159,640 KB |
ソースコード
def scc(N,edges): M=len(edges) start=[0]*(N+1) elist=[0]*M for e in edges: start[e[0]+1]+=1 for i in range(1,N+1): start[i]+=start[i-1] counter=start[:] for e in edges: elist[counter[e[0]]]=e[1] counter[e[0]]+=1 visited=[] low=[0]*N Ord=[-1]*N ids=[0]*N NG=[0,0] def dfs(v): stack=[(v,-1,0),(v,-1,1)] while stack: v,bef,t=stack.pop() if t: if bef!=-1 and Ord[v]!=-1: low[bef]=min(low[bef],Ord[v]) stack.pop() continue low[v]=NG[0] Ord[v]=NG[0] NG[0]+=1 visited.append(v) for i in range(start[v],start[v+1]): to=elist[i] if Ord[to]==-1: stack.append((to,v,0)) stack.append((to,v,1)) else: low[v]=min(low[v],Ord[to]) else: if low[v]==Ord[v]: while(True): u=visited.pop() Ord[u]=N ids[u]=NG[1] if u==v: break NG[1]+=1 low[bef]=min(low[bef],low[v]) for i in range(N): if Ord[i]==-1: dfs(i) for i in range(N): ids[i]=NG[1]-1-ids[i] group_num=NG[1] counts=[0]*group_num for x in ids: counts[x]+=1 groups=[[] for i in range(group_num)] for i in range(N): groups[ids[i]].append(i) return groups N=int(input()) G=[] X=[(0,-1)] INF=10**15 for i in range(1,N): l,a=map(int,input().split()) X.append((l,a-1)) G.append((i,a-1)) S=scc(N,G) for i in range(len(S)): if len(S[i])>1: for j in range(len(S[i])): X[S[i][j]]=(INF,0) import sys sys.setrecursionlimit(10**6) L=[-1]*N G2=[[] for i in range(N)] for i in range(1,N): G2[i].append(X[i][1]) def dfs(n): if L[n]>=0: return L[n] L[n]=X[n][0] for i in range(len(G2[n])): L[n]=max(L[n],dfs(G2[n][i])) return L[n] for i in range(N): dfs(i) C=sorted(L) from bisect import * Q=int(input()) for i in range(Q): t,x=map(int,input().split()) if t==1: print(bisect_right(C,x)) else: if L[x-1]>=INF: print(-1) else: print(L[x-1])