結果
| 問題 |
No.788 トラックの移動
|
| コンテスト | |
| ユーザー |
a
|
| 提出日時 | 2019-03-06 21:24:17 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,455 bytes |
| コンパイル時間 | 1,863 ms |
| コンパイル使用メモリ | 177,252 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-23 14:39:21 |
| 合計ジャッジ時間 | 2,537 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 1 WA * 13 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
void solve()
{
int n, m, l;
cin >> n >> m >> l;
l--;
vector<int> ts(n), ds(n, 1<<20);
for (int i = 0; i < n; i++)
{
cin >> ts[i];
}
vector<pair<int, int>> g[n];
while(m--)
{
int u, v, w;
cin >> u >> v >> w;
u--, v--;
g[u].emplace_back(v, w);
g[v].emplace_back(u, w);
}
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
pq.push(make_pair(0, l));
ds[l] = 0;
while (!pq.empty())
{
auto p = pq.top();
pq.pop();
int v = p.second, x = p.first;
for (auto np : g[v])
{
int nv = np.first, nw = np.second;
if (ds[nv] <= x + nw)
continue;
ds[nv] = x + nw;
pq.push(make_pair(ds[nv], nv));
}
}
long ans = LONG_MAX;
for (int s = 0; s < n; s++)
{
vector<int> d(n, 1<<20);
pq.push(make_pair(0, s));
d[s] = 0;
while(!pq.empty())
{
auto p = pq.top();
pq.pop();
int v = p.second, x = p.first;
for (auto np : g[v])
{
int nv = np.first, nw = np.second;
if (d[nv] <= x + nw) continue;
d[nv] = x + nw;
pq.push(make_pair(d[nv], nv));
}
}
/*
for (int dx : d){ cout << dx << ' ';}
cout << endl;
*/
long res = 0;
int p = 0;
for (int j = 0; j < n; j++)
{
res += 2*ts[j]*d[j];
p = min(p, ds[j] - d[j]);
}
ans = min(ans, res+p);
//cout << res << ' ' << p << endl;
}
cout << ans << endl;
}
int main(void)
{
solve();
//cout << "yui(*-v・)yui" << endl;
return 0;
}
a