結果
| 問題 |
No.1812 Uribo Road
|
| コンテスト | |
| ユーザー |
Haa
|
| 提出日時 | 2022-01-14 22:32:34 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,538 bytes |
| コンパイル時間 | 2,052 ms |
| コンパイル使用メモリ | 190,476 KB |
| 実行使用メモリ | 917,792 KB |
| 最終ジャッジ日時 | 2024-11-20 12:18:21 |
| 合計ジャッジ時間 | 69,842 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 20 TLE * 9 MLE * 1 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:54:33: warning: narrowing conversion of 'i' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
54 | g[a].push_back(edge{b,c,i});
| ^
main.cpp:55:33: warning: narrowing conversion of 'i' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
55 | 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];
unordered_map<int,ll> d;
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.find(to)==d.end())
d[to]=INF;
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)*(1<<k)+(1<<k)-1;
cout << d[p] << endl;
return 0;
}
Haa