結果
| 問題 |
No.788 トラックの移動
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-02-12 09:01:37 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 763 ms / 2,000 ms |
| コード長 | 2,286 bytes |
| コンパイル時間 | 2,102 ms |
| コンパイル使用メモリ | 181,740 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-12-15 07:03:28 |
| 合計ジャッジ時間 | 6,185 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 |
ソースコード
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
typedef long long Weight;
struct Edge {
int from, to;
Weight wei;
Edge(int from_, int to_, Weight wei_) :from(from_), to(to_), wei(wei_) {}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
const Weight INFW = numeric_limits<Weight>::max();
vector<Weight> dijkstra(const Graph &G, int src) {
typedef pair<Weight, int> pwi;
priority_queue<pwi, vector<pwi>, greater<pwi>> pq;
pq.push(mp(0, src));
int V = (int)G.size();
vector<Weight> res(V, -1);
while (pq.size()) {
auto p = pq.top(); pq.pop();
Weight d = p.first;
int v = p.second;
if (res[v] > -1)continue;
res[v] = d;
for (const auto &edge : G[v]) {
int to = edge.to;
Weight wei = edge.wei;
pq.push(make_pair(d + wei, to));
}
}
return res;
}
int N, M, L;
void solve() {
cin >> N >> M >> L;
--L;
vi T(N);
Graph G(N);
int pos = 0;
rep(i, N) {
cin >> T[i];
if (T[i] > 0)pos++;
}
if (pos <= 1) {
cout << 0 << endl;
return;
}
rep(i, M) {
int a, b, c;
cin >> a >> b >> c;
--a; --b;
G[a].emplace_back(a, b, c);
G[b].emplace_back(b, a, c);
}
vll dl = dijkstra(G, L);
ll ans = INFW;
rep(i, N) {
vll d = dijkstra(G, i);
ll sm = 0, mi = INFW;
rep(j, N) {
sm += d[j] * 2 * T[j];
if (T[j] > 0)smin(mi, dl[j] - d[j]);
}
sm += mi;
smin(ans, sm);
}
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(15);
solve();
return 0;
}