結果
問題 |
No.845 最長の切符
|
ユーザー |
![]() |
提出日時 | 2019-06-28 23:19:49 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,246 bytes |
コンパイル時間 | 888 ms |
コンパイル使用メモリ | 84,156 KB |
実行使用メモリ | 13,884 KB |
最終ジャッジ日時 | 2024-07-02 05:11:00 |
合計ジャッジ時間 | 6,406 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 TLE * 1 -- * 14 |
ソースコード
#include <iostream> #include <cstring> #include <vector> #include <set> #include <list> #include <map> #include <queue> #include <deque> #include <algorithm> #include <utility> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll,ll> pll; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; #define for1(i,n) for (ll i=0;i<(n);i++) #define for2(i,m,n) for (ll i=(m);i<(n);i++) #define for3(i,m,n,d) for (ll i=(m);i<(n);i+=(d)) #define DEBUG 0 #define INF 1e18 ll N,M; vector<vector<pll>> to(16); ll dfs(ll sc, ll loc, ll arr) { if ((arr & (1LL << loc)) != 0) { return -INF; } arr |= (1LL << loc); ll ret = sc; for (auto t : to[loc]) { if ((arr & (1LL << t.first)) == 0) { ret = max(ret, dfs(sc + t.second, t.first, arr)); } } return ret; } void solve() { cin >> N >> M; for1(i,M) { ll a,b,c; cin >> a >> b >> c; --a; --b; to[a].push_back(make_pair(b,c)); to[b].push_back(make_pair(a,c)); } ll ans = 0; // 駅iから出発する for1(i,N) { ans = max(ans,dfs(0,i,0)); } cout << ans << endl; } int main() { do { solve(); } while (DEBUG); }