結果
問題 | No.2630 Colorful Vertices and Cheapest Paths |
ユーザー | Nzt3 |
提出日時 | 2024-02-12 00:21:33 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,019 ms / 2,500 ms |
コード長 | 2,168 bytes |
コンパイル時間 | 250 ms |
コンパイル使用メモリ | 82,360 KB |
実行使用メモリ | 85,004 KB |
最終ジャッジ日時 | 2024-09-28 17:47:31 |
合計ジャッジ時間 | 16,159 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 535 ms
80,376 KB |
testcase_01 | AC | 847 ms
82,884 KB |
testcase_02 | AC | 818 ms
82,844 KB |
testcase_03 | AC | 74 ms
76,532 KB |
testcase_04 | AC | 45 ms
65,344 KB |
testcase_05 | AC | 80 ms
76,440 KB |
testcase_06 | AC | 443 ms
78,784 KB |
testcase_07 | AC | 656 ms
81,784 KB |
testcase_08 | AC | 621 ms
80,916 KB |
testcase_09 | AC | 676 ms
81,688 KB |
testcase_10 | AC | 1,010 ms
85,004 KB |
testcase_11 | AC | 1,016 ms
84,384 KB |
testcase_12 | AC | 1,019 ms
84,436 KB |
testcase_13 | AC | 1,015 ms
84,904 KB |
testcase_14 | AC | 1,002 ms
84,856 KB |
testcase_15 | AC | 759 ms
80,936 KB |
testcase_16 | AC | 768 ms
80,300 KB |
testcase_17 | AC | 798 ms
80,648 KB |
testcase_18 | AC | 467 ms
79,484 KB |
testcase_19 | AC | 601 ms
80,616 KB |
testcase_20 | AC | 544 ms
80,188 KB |
testcase_21 | AC | 661 ms
81,732 KB |
ソースコード
class dsu(): n=1 parent_or_size=[-1 for i in range(n)] def __init__(self,N): self.n=N self.parent_or_size=[-1 for i in range(N)] def merge(self,a,b): assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n) assert 0<=b<self.n, "0<=b<n,b={0},n={1}".format(b,self.n) x=self.leader(a) y=self.leader(b) if x==y: return x if (-self.parent_or_size[x]<-self.parent_or_size[y]): x,y=y,x self.parent_or_size[x]+=self.parent_or_size[y] self.parent_or_size[y]=x return x def same(self,a,b): assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n) assert 0<=b<self.n, "0<=b<n,b={0},n={1}".format(b,self.n) return self.leader(a)==self.leader(b) def leader(self,a): assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n) if (self.parent_or_size[a]<0): return a self.parent_or_size[a]=self.leader(self.parent_or_size[a]) return self.parent_or_size[a] def size(self,a): assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n) return -self.parent_or_size[self.leader(a)] def groups(self): leader_buf=[0 for i in range(self.n)] group_size=[0 for i in range(self.n)] for i in range(self.n): leader_buf[i]=self.leader(i) group_size[leader_buf[i]]+=1 result=[[] for i in range(self.n)] for i in range(self.n): result[leader_buf[i]].append(i) result2=[] for i in range(self.n): if len(result[i])>0: result2.append(result[i]) return result2 N,M=map(int,input().split()) E=[] for i in range(M): E.append(list(map(lambda x:int(x)-1,input().split()))) C=list(map(lambda x:int(x)-1,input().split())) W=list(map(int,input().split())) cost=[0]*(1<<10) for i in range(1<<10): for j in range(10): if i>>j&1: cost[i]+=W[j] Q=int(input()) ans=[10**12]*Q Qs=[] for i in range(Q): U,V=map(int,input().split()) U-=1 V-=1 Qs.append([U,V]) for i in range(1<<10): u=dsu(N) for j in E: if (i>>C[j[0]])&(i>>C[j[1]])&1: u.merge(j[0],j[1]) for j in range(Q): if u.same(Qs[j][0],Qs[j][1]): ans[j]=min(ans[j],cost[i]) for i in ans: if(i==10**12): i=-1 print(i)