結果
| 問題 |
No.788 トラックの移動
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-02-08 22:25:04 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 504 ms / 2,000 ms |
| コード長 | 3,205 bytes |
| コンパイル時間 | 1,459 ms |
| コンパイル使用メモリ | 174,092 KB |
| 実行使用メモリ | 34,816 KB |
| 最終ジャッジ日時 | 2024-12-15 07:00:02 |
| 合計ジャッジ時間 | 4,736 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 |
ソースコード
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
using namespace std;
typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;
const int MAX_N = 2005;
template<typename T> class Dijkstra {
public:
struct edge{
int to; T cost;
};
int V;
vector<vector<edge> > G;
vector<vector<T> > d;
using pti = pair<T,int>;
Dijkstra(int node_size) : V(node_size), G(V), d(V, vector<T>(V, numeric_limits<T>::max())){}
//無向グラフの場合
void add_edge(int u,int v,T cost){
G[u].pb((edge){v,cost}),G[v].pb((edge){u,cost});
}
void solve(){
rep(i,V){
priority_queue<pti,vector<pti>,greater<pti> > que;
d[i][i] = 0;
que.push(pti(0,i));
while(!que.empty()){
pti p = que.top();
que.pop();
int v = p.second;
if(d[i][v] < p.first) continue;
for(auto& w : G[v]){
if(d[i][w.to] > d[i][v] + w.cost){
d[i][w.to] = d[i][v] + w.cost;
que.push(pti(d[i][w.to],w.to));
}
}
}
}
}
};
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int n,m,L;
cin >> n >> m >> L;
L--;
vl t(n);
int cnt = 0;
rep(i,n){
cin >> t[i];
if(t[i] > 0){
cnt++;
}
}
Dijkstra<ll> dj(n);
rep(i,m){
int a,b,c;
cin >> a >> b >> c;
dj.add_edge(a-1,b-1,c);
}
if(cnt == 1){
cout << "0\n";
return 0;
}
dj.solve();
ll res = (1LL << 61);
rep(i,n){
ll hoge = 0;
rep(j,n){
hoge += 2*t[j]*dj.d[i][j];
}
ll ch = (1LL << 61);
rep(j,n){
if(t[j] > 0){
cmn(ch, dj.d[L][j]+dj.d[j][i]-2*dj.d[i][j]);
}else{
cmn(ch, dj.d[L][j]+dj.d[j][i]);
}
}
cmn(res, hoge+ch);
}
cout << res << "\n";
return 0;
}