結果

問題 No.788 トラックの移動
ユーザー utouto97utouto97
提出日時 2019-02-08 23:10:27
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,646 bytes
コンパイル時間 1,247 ms
コンパイル使用メモリ 150,872 KB
実行使用メモリ 35,044 KB
最終ジャッジ日時 2023-09-14 03:56:22
合計ジャッジ時間 4,476 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 426 ms
34,764 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 102 ms
19,376 KB
testcase_05 AC 419 ms
34,780 KB
testcase_06 AC 428 ms
35,044 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 76 ms
34,776 KB
testcase_16 AC 449 ms
34,768 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:85:35: warning: ‘x’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     ans = min(ans, tmp+lmin-d[i][x]);
                             ~~~~~~^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define foreach(u,v) for(auto (u) : (v))
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define int long long

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;

const int inf = 1e9;
const ll linf = 1LL<<60;
const ll mod = 1e9 + 7;
const double eps = 1e-9;

/*
*/

int n, m, l, t[2000];
vector<pii> es[2000];
ll d[2000][2000];

void dijkstra(int s)
{
  priority_queue<pll, vector<pll>, greater<pll>> que;
  fill(d[s], d[s]+n, linf);
  d[s][s] = 0;
  que.push(mp(0LL, s));

  while(!que.empty()){
    pll p = que.top();
    que.pop();
    if(d[s][p.second] < p.first) continue;
    foreach(e, es[p.second]){
      if(d[s][e.first] > d[s][p.second] + e.second){
        d[s][e.first] = d[s][p.second] + e.second;
        que.push(mp(d[s][e.first], e.first));
      }
    }
  }
}

signed main()
{
  cin >> n >> m >> l;
  rep(i, n){
    cin >> t[i];
  }
  l--;

  rep(i, m){
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    es[a].pb(mp(b, c));
    es[b].pb(mp(a, c));
  }

  rep(i, n){
    dijkstra(i);
  }

  ll ans = linf;
  rep(i, n){
    ll tmp = 0, lmin = d[l][i], x;
    rep(j, n){
      tmp += 2*t[j]*d[i][j];
      if(t[j] > 0)
        if(lmin > d[l][j]){
          lmin = d[l][j];
          x = j;
        }
        //lmin = min(lmin, d[l][j]);
    }
    ans = min(ans, tmp+lmin-d[i][x]);
  }

  cout << ans << endl;

  return 0;
}
0