結果
問題 |
No.1813 Magical Stones
|
ユーザー |
![]() |
提出日時 | 2022-01-14 22:35:04 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,459 bytes |
コンパイル時間 | 2,479 ms |
コンパイル使用メモリ | 185,576 KB |
実行使用メモリ | 1,427,284 KB |
最終ジャッジ日時 | 2024-11-20 12:44:22 |
合計ジャッジ時間 | 206,107 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | MLE * 4 |
other | TLE * 3 MLE * 37 |
コンパイルメッセージ
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}); | ^
ソースコード
#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; }