結果
| 問題 |
No.788 トラックの移動
|
| コンテスト | |
| ユーザー |
emthrm
|
| 提出日時 | 2019-02-12 02:48:00 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,410 bytes |
| コンパイル時間 | 1,444 ms |
| コンパイル使用メモリ | 135,272 KB |
| 最終ジャッジ日時 | 2025-01-06 21:08:05 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 WA * 2 |
ソースコード
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/
template <typename T, const T TINF>
struct Dijkstra {
struct Edge {
int src, dst;
T cost;
Edge(int dst_, T cost_ = 0) : src(-1), dst(dst_), cost(cost_) {}
Edge(int src_, int dst_, T cost_) : src(src_), dst(dst_), cost(cost_) {}
inline bool operator < (const Edge &rhs) { return cost < rhs.cost; }
inline bool operator <= (const Edge &rhs) { return cost <= rhs.cost; }
inline bool operator > (const Edge &rhs) { return cost > rhs.cost; }
inline bool operator >= (const Edge &rhs) { return cost >= rhs.cost; }
};
vector<vector<Edge> > graph;
vector<T> dist;
Dijkstra(int sz_) : sz(sz_), graph(sz_), dist(sz_, TINF), prev(sz_, -1) {}
void add(int src, int dst, T cost) { graph[src].emplace_back(Edge(dst, cost)); }
void build(int s) {
dist.assign(sz, TINF);
prev.assign(sz, -1);
dist[s] = 0;
priority_queue<pair<T, int>, vector<pair<T, int> >, greater<pair<T, int> > > que;
que.emplace(0, s);
while (!que.empty()) {
pair<T, int> pr = que.top(); que.pop();
int ver = pr.second;
if (dist[ver] < pr.first) continue;
for (Edge e : graph[ver]) {
if (dist[e.dst] > dist[ver] + e.cost) {
dist[e.dst] = dist[ver] + e.cost;
prev[e.dst] = ver;
que.emplace(dist[e.dst], e.dst);
}
}
}
}
vector<int> build_path(int t) {
vector<int> res;
for (; t != -1; t = prev[t]) res.emplace_back(t);
reverse(ALL(res));
return res;
}
private:
int sz;
vector<int> prev;
};
// Dijkstra<costの型, LINF> dij(sz) = 頂点数 sz の単一始点最短路を考える
// dij.graph = グラフ
// dij.dist[ver] = 始点から頂点 ver までの最短距離
// dij.add(src, dst, cost) = 始点 src, 終点 dst(, 重み cost)の辺をグラフに追加する
// dij.build(s) = 始点 start の単一始点最短路を求める
// dij.build_path(t) = 終点 t の最短路を求める
int main() {
cin.tie(0); ios::sync_with_stdio(false);
// freopen("input.txt", "r", stdin);
int n, m, l; cin >> n >> m >> l; --l;
vector<int> t(n); REP(i, n) cin >> t[i];
Dijkstra<long long, LINF> dij(n);
REP(i, m) {
int a, b; cin >> a >> b; --a; --b;
long long c; cin >> c;
dij.add(a, b, c);
dij.add(b, a, c);
}
vector<vector<long long> > d(n, vector<long long>(n, LINF));
REP(i, n) {
dij.build(i);
REP(j, n) d[i][j] = dij.dist[j];
}
long long ans = LINF;
REP(i, n) { // 集める交差点
long long tmp = 0;
REP(j, n) tmp += 2 * d[i][j] * t[j];
REP(j, n) ans = min(ans, tmp + d[l][j] + d[j][i] - (t[j] > 0 ? d[j][i] * 2 : 0));
}
cout << ans << '\n';
return 0;
}
emthrm