結果
| 問題 |
No.1812 Uribo Road
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2022-01-16 00:56:33 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,536 bytes |
| コンパイル時間 | 645 ms |
| コンパイル使用メモリ | 61,536 KB |
| 実行使用メモリ | 693,280 KB |
| 最終ジャッジ日時 | 2024-11-22 08:37:28 |
| 合計ジャッジ時間 | 54,992 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 22 TLE * 7 MLE * 1 |
ソースコード
/* -*- coding: utf-8 -*-
*
* 1812.cc: No.1812 Uribo Road - yukicoder
*/
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
/* constant */
const int MAX_N = 10000;
const int MAX_M = 20000;
const int MAX_K = 12;
const int KBITS = 1 << MAX_K;
const long long LINF = 1LL << 62;
/* typedef */
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<pii> vpii;
/* global variables */
vpii nbrs[MAX_N];
int ebs[MAX_M], cs[MAX_M];
ll ds[MAX_N * KBITS];
/* subroutines */
/* main */
int main() {
int n, m, k;
scanf("%d%d%d", &n, &m, &k);
int kbits = 1 << k, kmsk = kbits - 1;
for (int i = 0; i < k; i++) {
int ri;
scanf("%d", &ri), ri--;
ebs[ri] = 1 << i;
}
for (int i = 0; i < m; i++) {
int u, v;
scanf("%d%d%d", &u, &v, cs + i);
u--, v--;
nbrs[u].push_back(pii(v, i));
nbrs[v].push_back(pii(u, i));
}
fill(ds, ds + n * kbits, LINF);
ds[0] = 0;
priority_queue<pli> q;
q.push(pli(0, 0));
int gl = (n - 1) << k | kmsk;
while (! q.empty()) {
pli u = q.top(); q.pop();
ll ud = -u.first;
int up = u.second;
if (ds[up] != ud) continue;
if (up == gl) break;
int ui = up >> k, ub = up & kmsk;
for (auto ve: nbrs[ui]) {
int vi = ve.first, ei = ve.second;
int vb = ub | ebs[ei];
int vp = vi << k | vb;
ll vd = ud + cs[ei];
if (ds[vp] > vd) {
ds[vp] = vd;
q.push(pli(-vd, vp));
}
}
}
printf("%lld\n", ds[gl]);
return 0;
}
tnakao0123