結果

問題 No.3756 Udon Network
ユーザー tsunamayo123
提出日時 2026-09-12 15:36:48
言語 PyPy3
(7.3.23 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 1,273 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 65 ms
コンパイル使用メモリ 82,628 KB
実行使用メモリ 247,124 KB
最終ジャッジ日時 2026-10-09 17:43:41
合計ジャッジ時間 14,602 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
サブタスク 配点 結果
Example 0 % WA * 8
Subtask $1$ 2 % WA * 15
Subtask $2$ 4 % WA * 22
Subtask $3$ 8 % WA * 3 TLE * 1 -- * 5
Subtask $4$ 16 % WA * 2 -- * 8
Subtask $5$ 32 % WA * 3 -- * 7
Subtask $6$ 38 % WA * 22 TLE * 1 -- * 30
合計 4 * 0% = 0 点
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

# 部分点2

import sys
from collections import deque

input = sys.stdin.readline

N,M,Q = map(int, input().split())

A = list(map(int, input().split()))
A = [x-1 for x in A]

G = [[] for _ in range(N)]
W = {0} # 答えは0かw_jなので、添字で二分探索できる

for i in range(M):
    u,v,w = map(int, input().split())
    G[u-1].append((v-1,w))
    G[v-1].append((u-1,w))
    W.add(w)

W = sorted(W)

for i in range(Q):
    s,c = map(int, input().split())
    s-=1

    ok=len(W)
    ng=-1
    while(ok-ng>1):
        mid = (ok+ng)//2
        D=W[mid]

        visited = [0]*N
        flag = [0]*N
        visited[s]=True
        flag[A[s]]=True

        que = deque([s])
        
        t=0

        while que:
            m=que.popleft()

            for nex,w in G[m]:
                if ((w<=D) and visited[nex]==False):
                    visited[nex]=True
                    que.append(nex)                
                    if not flag[A[nex]]:
                        flag[A[nex]]=True
                        t+=1
                        if t>=c:
                            break
                        

        if t>=c:
            ok=mid
        else:
            ng=mid

    if ok == len(W):
        print(-1)
    else:
        print(W[ok])
0