結果

問題 No.2630 Colorful Vertices and Cheapest Paths
ユーザー Nzt3Nzt3
提出日時 2024-02-11 17:50:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,099 bytes
コンパイル時間 2,339 ms
コンパイル使用メモリ 213,772 KB
実行使用メモリ 27,872 KB
最終ジャッジ日時 2024-02-11 17:50:23
合計ジャッジ時間 9,967 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
// TLE
int main(){
  int N,M;
  cin>>N>>M;
  vector G(N,vector(0,0));
  for(int i=0;i<M;i++){
    int A,B;
    cin>>A>>B;
    --A,--B;
    G[A].push_back(B);
    G[B].push_back(A);
  }
  vector C(N,0);
  for(int &i:C)cin>>i,--i;
  vector W(10,0ll);
  for(ll &i:W)cin>>i;
  vector cost(1<<10,0ll);
  for(int i=0;i<1<<10;i++){
    for(int j=0;j<10;j++){
      if(i>>j&1)cost[i]+=W[j];
    }
  }
  int Q;
  cin>>Q;
  vector dp(1<<10,vector(N,Q));
  while(Q--){
    int U,V;
    cin>>U>>V;
    --U,--V;
    ll ans=-1;
    auto comp=[&](array<int,2> a,array<int,2> b){
      return cost[a[0]]>cost[b[0]];
    };
    priority_queue<array<int,2>,vector<array<int,2>>,decltype(comp)> pq(comp);
    dp[1<<C[U]][U]=Q;
    pq.push({1<<C[U],U});
    while(pq.size()){
      auto [s,v]=pq.top();
      pq.pop();
      if(v==V){
        ans=cost[s];
        break;
      }
      for(int i:G[v]){
        if(dp[s|(1<<C[i])][i]>Q){
          dp[s|(1<<C[i])][i]=Q;
          pq.push({s|(1<<C[i]),i});
        }
      }
    }
    cout<<ans<<'\n';
  }
}
0