結果

問題 No.807 umg tours
ユーザー oevloevl
提出日時 2019-03-22 22:47:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,123 bytes
コンパイル時間 1,859 ms
コンパイル使用メモリ 174,652 KB
実行使用メモリ 12,232 KB
最終ジャッジ日時 2023-10-19 09:58:05
合計ジャッジ時間 12,818 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
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, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i >= n; --i)
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

struct edge {
  int to, cost;
};
typedef pair<ll, ll> P;

ll mncost1 = 1e18;
ll mncost2 = 1e18;

int used[101010];
int N, M;
vector<vector<edge>> G;
void dfs(int s, int v, int mx, ll cost) {
  if(v == 0) {
    chmin(mncost1,cost);
    chmin(mncost2,cost - mx);
    return;
  }
  if(used[v]) return;
  used[v] = 1;
  for(auto nv : G[v]) {
    dfs(s, nv.to, max(mx, nv.cost), cost + nv.cost);
  }
  used[v] = 0;
}

int main() {
  cin >> N >> M;
  G.assign(N, vector<edge>());
  rep(i, 0, M) {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    G[a].push_back({b, c});
    G[b].push_back({a, c});
  }
  rep(i, 0, N) {
    dfs(i, i, 0, 0);
    ll cost1 = mncost1;
    ll cost2 = mncost2;
    mncost1 = mncost2 = 1e18;
    cout << cost1 + cost2 << "\n";
  }
  return 0;
}
0