結果

問題 No.788 トラックの移動
ユーザー rookzenorookzeno
提出日時 2019-02-09 00:17:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,862 bytes
コンパイル時間 1,716 ms
コンパイル使用メモリ 181,264 KB
実行使用メモリ 38,396 KB
最終ジャッジ日時 2023-09-14 04:01:09
合計ジャッジ時間 4,565 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 399 ms
38,364 KB
testcase_01 AC 2 ms
5,436 KB
testcase_02 AC 2 ms
5,668 KB
testcase_03 AC 2 ms
5,460 KB
testcase_04 AC 95 ms
21,348 KB
testcase_05 AC 381 ms
38,396 KB
testcase_06 AC 400 ms
38,372 KB
testcase_07 AC 2 ms
5,576 KB
testcase_08 AC 2 ms
5,452 KB
testcase_09 AC 1 ms
5,448 KB
testcase_10 AC 2 ms
5,640 KB
testcase_11 AC 2 ms
5,388 KB
testcase_12 AC 1 ms
5,452 KB
testcase_13 AC 2 ms
5,392 KB
testcase_14 AC 2 ms
5,368 KB
testcase_15 WA -
testcase_16 AC 412 ms
38,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long   // aaaaaaaaaaaaaaaaaa
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define in(s,x) s.find(x) != s.end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define SIZE(buff) (sizeof(buff)/sizeof(buff[0]))
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<pair<int,int>> VPII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
void chmin(int64_t& a, int64_t b){
    a = min(a, b);
}
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
template<typename T, typename U>ostream& operator << (ostream& os, pair<T, U>& pair_var)
{os << "(" << pair_var.first << ", " << pair_var.second << ")";return os;}

// head
int m,n,k,res,tmp,tmp2,tmp3,h,w;
int a[100001] = {};
int b[100010] = {};
int r[100001][25];
deque<PII> que;
string s;
map<int,VPII> kukan;
vector<PII> g[3000];
//int dp[200000];
int flag;
//VPII g2[200000];
int cost[200005];
ll dp[500][510] = {};
//VVI g(200005);
int d[2010][2010];

signed main() {
	cin.tie(0);
    ios::sync_with_stdio(false);
	cin>>n>>m>>k;
    k-=1;
    rep(i,0,n) cin>>a[i];
    rep(i,0,m){
        cin>>tmp>>tmp2>>tmp3;
        g[tmp-1].pb({tmp2-1,tmp3});
        g[tmp2-1].pb({tmp-1,tmp3});
    }
	
	rep(i,0,n)rep(j,0,n) d[i][j] = 1LL<<50;
    rep(i,0,n){
	d[i][i] = 0;
    priority_queue<pair<ll, ll> > pque;
	pque.push({0,i});
	while (!pque.empty()){
		PII p = pque.top();pque.pop();
		int prov_cost = p.first;
		int src = p.second;
		if(d[i][src]<prov_cost) continue;
		rep(l,0,g[src].size()){
			int dest = g[src][l].first;
			int weight = g[src][l].second;
			if ((d[i][dest] > d[i][src] + weight)){
				d[i][dest] = d[i][src] + weight;
				pque.push({-d[i][dest],dest});
			}
		}
	}
    }
    vector<PII> ti;
    rep(i,0,n) ti.pb({d[k][i],i});
    sort(all(ti));
    int r=-1;
    int t = -1;
    res = 1LL<<50;
    int flag = 1;
    rep(i,0,n){
        if (a[ti[i].se]){
            if (flag == 1){r = ti[i].se;flag=0;}
            else{t = ti[i].se;break;}
        }
        else{
            continue;
        }
    }
    if(t==-1 || r==-1){cout<<0<<endl;exit(0);}
    rep(i,0,n){
        tmp = 0;
        int sai;
        if (r == i) sai = t;
        else sai = r;
        tmp += d[k][sai] + d[sai][i];
        rep(j,0,n){
            if(j==sai){tmp+=(a[j]-1)*d[i][j]*2;}
            else tmp+=a[j]*d[i][j]*2;
        }
        res = min(res,tmp);
    }
    cout<<res<<endl;
}
0