結果

問題 No.788 トラックの移動
ユーザー koprickykopricky
提出日時 2019-02-08 22:06:23
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 3,072 bytes
コンパイル時間 2,802 ms
コンパイル使用メモリ 158,216 KB
実行使用メモリ 35,168 KB
最終ジャッジ日時 2023-09-14 03:40:59
合計ジャッジ時間 4,992 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 483 ms
35,168 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 107 ms
11,480 KB
testcase_05 AC 470 ms
34,892 KB
testcase_06 AC 482 ms
34,872 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 149 ms
34,864 KB
testcase_16 AC 521 ms
34,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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);
    rep(i,n){
        cin >> t[i];
    }
    Dijkstra<ll> dj(n);
    rep(i,m){
        int a,b,c;
        cin >> a >> b >> c;
        dj.add_edge(a-1,b-1,c);
    }
    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;
}
0