結果
| 問題 |
No.845 最長の切符
|
| コンテスト | |
| ユーザー |
MarcusAureliusAntoninus
|
| 提出日時 | 2019-06-28 22:27:08 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 65 ms / 3,000 ms |
| コード長 | 919 bytes |
| コンパイル時間 | 2,006 ms |
| コンパイル使用メモリ | 199,460 KB |
| 最終ジャッジ日時 | 2025-01-07 05:33:48 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:15:31: warning: format ‘%lld’ expects argument of type ‘long long int*’, but argument 4 has type ‘int64_t*’ {aka ‘long int*’} [-Wformat=]
15 | scanf("%d%d%lld", &a, &b, &c);
| ~~~^ ~~
| | |
| | int64_t* {aka long int*}
| long long int*
| %ld
main.cpp:36:20: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 2 has type ‘int64_t’ {aka ‘long int’} [-Wformat=]
36 | printf("%lld\n", max);
| ~~~^ ~~~
| | |
| | int64_t {aka long int}
| long long int
| %ld
main.cpp:6:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
6 | scanf("%d%d", &N, &M);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:15:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
15 | scanf("%d%d%lld", &a, &b, &c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
int main()
{
int N, M;
scanf("%d%d", &N, &M);
using vi = std::vector<int64_t>;
using vvi = std::vector<vi>;
vvi graph(N, vi(N));
for (int i{}; i < M; i++)
{
int a, b;
int64_t c;
scanf("%d%d%lld", &a, &b, &c);
a--; b--;
graph[a][b] = std::max(graph[a][b], c);
graph[b][a] = std::max(graph[b][a], c);
}
vvi dp(1 << N, vi(N, -1));
for (int i{}; i < N; i++)
dp[1 << i][i] = 0;
int64_t max{};
for (int set_i{1}; set_i < (1 << N); set_i++)
{
for (int now_i{}; now_i < N; now_i++)
{
max = std::max(max, dp[set_i][now_i]);
if ((~set_i >> now_i & 1) || dp[set_i][now_i] < 0)
continue;
for (int next_i{}; next_i < N; next_i++)
if ((~set_i >> next_i & 1) && graph[now_i][next_i] > 0)
dp[set_i | (1 << next_i)][next_i] = std::max(dp[set_i | (1 << next_i)][next_i], dp[set_i][now_i] + graph[now_i][next_i]);
}
}
printf("%lld\n", max);
return 0;
}
MarcusAureliusAntoninus