結果

問題 No.2630 Colorful Vertices and Cheapest Paths
ユーザー tassei903tassei903
提出日時 2024-02-16 23:24:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,213 ms / 2,500 ms
コード長 1,446 bytes
コンパイル時間 345 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 158,644 KB
最終ジャッジ日時 2024-02-16 23:26:49
合計ジャッジ時間 29,725 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 622 ms
95,704 KB
testcase_01 AC 1,387 ms
117,988 KB
testcase_02 AC 1,891 ms
150,828 KB
testcase_03 AC 76 ms
74,560 KB
testcase_04 AC 55 ms
66,528 KB
testcase_05 AC 81 ms
74,572 KB
testcase_06 AC 438 ms
86,728 KB
testcase_07 AC 2,007 ms
157,040 KB
testcase_08 AC 1,748 ms
148,168 KB
testcase_09 AC 1,924 ms
158,300 KB
testcase_10 AC 2,087 ms
158,472 KB
testcase_11 AC 2,213 ms
158,348 KB
testcase_12 AC 2,103 ms
158,340 KB
testcase_13 AC 2,086 ms
158,188 KB
testcase_14 AC 2,048 ms
158,540 KB
testcase_15 AC 703 ms
78,160 KB
testcase_16 AC 669 ms
78,032 KB
testcase_17 AC 691 ms
78,032 KB
testcase_18 AC 858 ms
100,320 KB
testcase_19 AC 1,383 ms
139,536 KB
testcase_20 AC 1,225 ms
128,384 KB
testcase_21 AC 1,757 ms
158,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes")
no = lambda :print("no");No = lambda :print("No")
#######################################################################
from collections import deque
N,M=map(int,input().split())
G=[[] for _ in range(N)]
for i in range(M):
    a,b=map(int,input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
C=list(map(int,input().split()))
W=list(map(int,input().split()))
Group=[[-1]*N for _ in range(2**10)]
cost=[0]*(2**10)
for i in range(1,2**10):
    T=0
    w=0
    S=set()
    c=0
    for j in range(10):
        if((i>>j)&1):
            S.add(j+1)
            c+=W[j]
    cost[i]=c
    # que=deque([0])
    # Group[i][0]=w
    while T<N:
        que=[T]
        Group[i][T]=w
        while len(que):
            p=que.pop()
            for q in G[p]:
                if(C[p] in S and C[q] in S and Group[i][q]==-1):
                    Group[i][q]=Group[i][p]
                    que.append(q)
        while T<N and Group[i][T]!=-1:
            T+=1
        w+=1
Q=int(input())
answers=[]
for _ in range(Q):
    ans=-1
    u,v=map(int,input().split())
    u-=1
    v-=1
    for j in range(1,2**10):
        if(Group[j][u]==Group[j][v]):
            if(ans==-1 or cost[j]<ans):
                ans=cost[j]
    answers.append(ans)
for ans in answers:
    print(ans)
0