結果

問題 No.1813 Magical Stones
ユーザー HaaHaa
提出日時 2022-01-14 22:35:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,459 bytes
コンパイル時間 1,854 ms
コンパイル使用メモリ 186,924 KB
実行使用メモリ 707,012 KB
最終ジャッジ日時 2024-04-30 16:05:29
合計ジャッジ時間 9,526 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 MLE -
testcase_02 MLE -
testcase_03 TLE -
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 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:52:33: warning: narrowing conversion of 'i' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   52 |         g[a].push_back(edge{b,c,i});
      |                                 ^
main.cpp:53:33: warning: narrowing conversion of 'i' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   53 |         g[b].push_back(edge{a,c,i});
      |                                 ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
template<typename T> bool chmax(T &x, const T &y) {return (x<y)?(x=y,true):false;};
template<typename T> bool chmin(T &x, const T &y) {return (x>y)?(x=y,true):false;};
constexpr ll MOD=1000000007;
constexpr ll INF=2e18;

int n, m, k;

struct edge { int to, cost, id; };
vector<edge> g[21000];
VI d(90000000,INF);
unordered_map<int,int> ri;

void dijkstra(int s){
    priority_queue<P,vector<P>,greater<P>> que;
    d[s]=0;
    que.push({0,s});
    while(!que.empty()){
        P p=que.top();
        que.pop();
        int v=p.second/(1<<k);
        int w=p.second%(1<<k);
        if(d[p.second]<p.first)
            continue;
        for(auto e:g[v]){
            int to=e.to*(1<<k)+w;
            if(ri[e.id]>0)
                to|=(1<<(ri[e.id]-1));
            if(d[to]>d[p.second]+e.cost){
                d[to]=d[p.second]+e.cost;
                que.push({d[to],to});
            }
        }
    }
}

int main(){
    cin >> n >> m >> k;
    VI r(k); REP(i,k) cin >> r[i];
    REP(i,k) ri[r[i]-1]=i+1;
    int a, b, c;
    REP(i,m){
        cin >> a >> b >> c;
        a--, b--;
        g[a].push_back(edge{b,c,i});
        g[b].push_back(edge{a,c,i});
    }
    dijkstra(0);
    int p=n*(1<<k)-1;
    cout << d[p] << endl;
    return 0;
}
0