結果
| 問題 |
No.845 最長の切符
|
| コンテスト | |
| ユーザー |
yakamoto
|
| 提出日時 | 2019-06-28 22:52:29 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,698 bytes |
| コンパイル時間 | 1,827 ms |
| コンパイル使用メモリ | 173,956 KB |
| 実行使用メモリ | 13,896 KB |
| 最終ジャッジ日時 | 2024-07-02 05:04:00 |
| 合計ジャッジ時間 | 6,596 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 TLE * 1 -- * 14 |
ソースコード
#include <bits/stdc++.h>
namespace DECLARATIONS {
using namespace std;
using ll = long long;
using PI = pair<int, int>;
template<class T> using V = vector<T>;
using VI = V<int>;
#define _1 first
#define _2 second
#ifdef MY_DEBUG
# define DEBUG(x) x
#else
# define DEBUG(x)
#endif
template<class T>
inline void debug(T &A) {
DEBUG(
for (const auto &a : A) {
cerr << a << " ";
}
cerr << '\n';
)
}
template<class T>
inline void debug_dim2(T &A) {
DEBUG(
for (const auto &as : A) {
debug(as);
}
)
}
template<typename ... Args>
inline void debug(const char *format, Args const &... args) {
DEBUG(
fprintf(stderr, format, args ...);
cerr << '\n';
)
}
template<typename ... Args>
string format(const std::string &fmt, Args ... args) {
size_t len = std::snprintf(nullptr, 0, fmt.c_str(), args ...);
std::vector<char> buf(len + 1);
std::snprintf(&buf[0], len + 1, fmt.c_str(), args ...);
return std::string(&buf[0], &buf[0] + len);
}
}
using namespace DECLARATIONS;
const int MOD = 1000000007;
template<class T>
class SegmentTree {
private:
int calcN(int x) {
int k = 1 << (31 - __builtin_clz(x));
return k == x ? k : k << 1;
}
public:
int N;
V<T> dat;
const T zero = (ll)-1e18;
inline T f(T a, T b) {
return max(a, b);
}
SegmentTree(int n): N(calcN(n)), dat(2 * this->N) {
if (zero != 0) std::fill(dat.begin(), dat.end(), zero);
}
void update(int i, T a) {
int ix = i + N;
dat[ix] = a;
while(ix > 1) {
int p = ix >> 1;
dat[p] = f(dat[ix], dat[ix ^ 1]);
ix = p;
}
}
/**
* [a, b)
*/
T query(int a, int b) {
T res = zero;
int l = a + N, r = b - 1 + N;
while(l <= r) {
if ((l&1)) res = f(res, dat[l]);
if (!(r&1)) res = f(res, dat[r]);
l = (l + 1) >> 1; // 右の子供なら右の親に移動
r = (r - 1) >> 1; // 左の子供なら左の親に移動
}
return res;
}
};
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, M;
cin >> N >> M;
V<VI> g(N, VI(N, -1));
for (int i = 0; i < M; ++i) {
int a, b, c;
cin >> a >> b >> c;
a--; b--;
g[a][b] = max(g[a][b], c);
g[b][a] = max(g[b][a], c);
}
function<int(int, int)> dfs = [&](int v, int mask) {
int res = 0;
for (int u = 0; u < N; ++u) {
if (g[v][u] != -1 && !(mask & (1 << u))) {
res = max(res, dfs(u, mask | (1 << u)) + g[v][u]);
}
}
return res;
};
int ans = 0;
for (int i = 0; i < N; ++i) {
ans = max(ans, dfs(i, 1 << i));
}
cout << ans;
return 0;
}
yakamoto