結果

問題 No.845 最長の切符
ユーザー cotton_fn_cotton_fn_
提出日時 2019-06-28 22:52:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,718 bytes
コンパイル時間 1,362 ms
コンパイル使用メモリ 126,900 KB
実行使用メモリ 9,672 KB
最終ジャッジ日時 2023-09-14 22:30:22
合計ジャッジ時間 7,301 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,752 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 895 ms
4,376 KB
testcase_11 AC 143 ms
4,376 KB
testcase_12 AC 20 ms
4,384 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n, m;
vector<vector<pair<i64, i64>>> g;
vector<vector<i64>> dp;

i64 dfs(i64 u, i64 s) {
  if (dp[u][s]) return dp[u][s];
  s |= 1 << (u - 1);
  i64 y = 0;
  for (const auto& p : g[u]) {
    i64 c, v;
    tie(c, v) = p;
    if (!(s & (1 << (v - 1)))) {
      y = max(y, c + dfs(v, s));
    }
  }
  return dp[u][s] = y;
}

int main() {
  cin >> n >> m;
  init_n(g, n + 1);
  for (i64 i = 0; i < m; ++i) {
    i64 a, b, c;
    cin >> a >> b >> c;
    g[a].emplace_back(c, b);
    g[b].emplace_back(c, a);
  }
  for (i64 u = 1; u <= n; ++u) {
    sort(begin(g[u]), end(g[u]), greater<pair<i64, i64>>());
  }
  init_n(dp, n + 1, vector<i64>(1 << n));
  for (i64 u = 1; u <= n; ++u) {
    dfs(u, 0);
  }
  i64 ans = 0;
  for (i64 u = 1; u <= n; ++u) {
    for (i64 d : dp[u]) ans = max(ans, d);
  }
  cout << ans << '\n';
  return 0;
}

0