結果
| 問題 |
No.788 トラックの移動
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-04-16 21:11:52 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,754 bytes |
| コンパイル時間 | 1,343 ms |
| コンパイル使用メモリ | 168,228 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-22 08:23:35 |
| 合計ジャッジ時間 | 6,559 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 3 |
| other | AC * 2 WA * 12 |
ソースコード
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
class Edge {
public:
ll t, w;
Edge(ll t, ll w): t(t), w(w) {}
};
ll N, M, L;
vector<Edge> g[2020];
void dijkstra(ll s, ll d[]) {
ll i, u;
ll clr[2020];
for(i=0; i<N; i++) {
d[i]=INF;
clr[i]=0;
}
priority_queue<P> q;
q.push(P(0, s));
d[s]=0;
while(q.size()) {
P f=q.top(); q.pop();
u=f.sc;
clr[u]=1;
if(d[u]<-f.ft) continue;
for(i=0; i<g[u].size(); i++) {
Edge &e=g[u][i];
if(clr[e.t]==0 && d[e.t]>d[u]+e.w) {
d[e.t]=d[u]+e.w;
q.push(P(-d[e.t], e.t));
}
}
}
}
int main(void) {
cin >> N >> M >> L;
L--;
ll c[2020];
ll i, j;
for(i=0; i<N; i++) {
cin >> c[i];
}
for(i=0; i<M; i++) {
ll a, b, c;
cin >> a >> b >> c;
a--; b--;
g[a].pb(Edge(b, c));
g[b].pb(Edge(a, c));
}
ll ans=INF;
for(i=0; i<N; i++) {
ll ds[2020]={};
dijkstra(i, ds);
ll t=0;
for(j=0; j<N; j++) {
t+=ds[j]*2*c[j];
}
ll dl[2020]={};
dijkstra(L, dl);
for(j=0; j<N; j++) {
ll tm=t;
if(c[j]==0) continue;
tm+=dl[j];
tm+=ds[j];
tm-=ds[j]*2;
c[j]--;
chmin(ans, tm);
}
ll f=1;
for(j=0; j<N; j++) {
if(j==i) continue;
if(c[j]>0) f=0;
}
if(f) ans=0;
}
pt(ans);
}