結果

問題 No.807 umg tours
ユーザー 48025254802525
提出日時 2019-03-23 21:30:25
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,358 bytes
コンパイル時間 1,813 ms
コンパイル使用メモリ 169,820 KB
実行使用メモリ 814,080 KB
最終ジャッジ日時 2023-10-24 22:49:59
合計ジャッジ時間 6,530 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 4 ms
6,284 KB
testcase_07 WA -
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 MLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
#define INF 1e9
typedef long long ll;
typedef pair<int, int> P;
typedef struct{
  int first;
  int second;
  int third;
}T;

//昇順
bool comp_Se(T& l, T& r){
  return l.second < r.second;
}
int N,M;
vector< vector<int> > cost;
vector<pair<int,int> > d;
vector<bool> used;
vector<int> ticket;

void dijkstra(){
  while(true){
    int v = -1;
    //まだ使われていない頂点のうち距離が最小のものを探す
    for(int u = 0; u < N; u++){
      if(!used[u] && (v == -1 || d[u].first < d[v].first) ) v = u;
    }
    if( v == -1) break;
    used[v] = true;
    for(int u = 0; u < N; u++){
      if(cost[u][v] != INF){
        d[u].first = min(d[u].first, d[v].first+cost[v][u]);
        d[u].second = min(d[u].second, d[v].second + min(ticket[v],cost[u][v]));
        ticket[u] = max(ticket[v],cost[u][v]);
      }
    }
  }
}

int main(void){
  cin >> N >> M;
  cost = vector<vector<int> >(M, vector<int>(M, INF));
  d = vector<pair<int,int> >(N,pair<int,int>(INF,INF));
  d[0] = pair<int,int>(0,0);
  used = vector<bool>(M,false);
  ticket = vector<int>(M,0);
  int i;
  REP(i,M){
    int x,y,z;
    cin >> x >> y >> z;
    cost[x-1][y-1] = z;
    cost[y-1][x-1] = z;
  }
  dijkstra();
  REP(i,N){
    cout << d[i].first+d[i].second << endl;
  }
  return 0;
}
0