結果
問題 | No.845 最長の切符 |
ユーザー |
![]() |
提出日時 | 2019-06-28 22:37:08 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 680 ms / 3,000 ms |
コード長 | 2,382 bytes |
コンパイル時間 | 1,728 ms |
コンパイル使用メモリ | 171,368 KB |
実行使用メモリ | 7,680 KB |
最終ジャッジ日時 | 2024-07-02 04:58:34 |
合計ジャッジ時間 | 4,844 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h>using namespace std;typedef long long signed int LL;typedef long long unsigned int LU;#define incID(i, l, r) for(LL i = (l) ; i < (r); ++i)#define incII(i, l, r) for(LL i = (l) ; i <= (r); ++i)#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)#define decII(i, l, r) for(LL i = (r) ; i >= (l); --i)#define inc(i, n) incID(i, 0, n)#define inc1(i, n) incII(i, 1, n)#define dec(i, n) decID(i, 0, n)#define dec1(i, n) decII(i, 1, n)#define inID(v, l, r) ((l) <= (v) && (v) < (r))#define inII(v, l, r) ((l) <= (v) && (v) <= (r))#define PB push_back#define EB emplace_back#define MP make_pair#define FI first#define SE second#define ALL(v) v.begin(), v.end()#define RALL(v) v.rbegin(), v.rend()template<typename T> bool setmin (T & a, T b) { if(b < a) { a = b; return true; } else { return false; } }template<typename T> bool setmax (T & a, T b) { if(b > a) { a = b; return true; } else { return false; } }template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }#define bit(b, i) (((b) >> (i)) & 1)#define BC __builtin_popcountll#define SC static_cast#define SI(v) SC<int>(v.size())#define SL(v) SC<LL >(v.size())#define RF(e, v) for(auto & e: v)#define ef else if#define UR assert(false)// ---- ----int n, m, dp[1 << 16][16], INF = 1e9;vector<pair<int, int>> g[16];int main() {cin >> n >> m;inc(i, m) {int a, b, c;cin >> a >> b >> c;a--; b--;g[a].EB(b, c);g[b].EB(a, c);}inc(b, 1 << n) {inc(i, n) {dp[b][i] = -INF;}}inc(i, n) { dp[1 << i][i] = 0; }inc(b, 1 << n) {inc(i, n) {RF(e, g[i]) {if(bit(b, e.FI)) { continue; }setmax(dp[b | (1 << e.FI)][e.FI], dp[b][i] + e.SE);}}}int ans = 0;inc(b, 1 << n) {inc(i, n) {setmax(ans, dp[b][i]);}}cout << ans << endl;return 0;}