結果
| 問題 | No.845 最長の切符 | 
| コンテスト | |
| ユーザー |  tnakao0123 | 
| 提出日時 | 2019-06-29 23:15:16 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 52 ms / 3,000 ms | 
| コード長 | 1,306 bytes | 
| コンパイル時間 | 755 ms | 
| コンパイル使用メモリ | 83,924 KB | 
| 実行使用メモリ | 7,808 KB | 
| 最終ジャッジ日時 | 2024-07-02 05:41:56 | 
| 合計ジャッジ時間 | 1,854 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 27 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:47:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   47 |   scanf("%d%d", &n, &m);
      |   ~~~~~^~~~~~~~~~~~~~~~
main.cpp:51:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   51 |     scanf("%d%d%d", &a, &b, &c);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
            
            ソースコード
/* -*- coding: utf-8 -*-
 *
 * 845.cc:  No.845 最長の切符 - yukicoder
 */
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;
/* constant */
const int MAX_N = 16;
const int NBITS = 1 << MAX_N;
/* typedef */
/* global variables */
int ds[MAX_N][MAX_N];
int dp[NBITS][MAX_N];
/* subroutines */
inline void setmax(int &a, int b) { if (a < b) a = b; }
/* main */
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    a--, b--;
    if (ds[a][b] < c) ds[a][b] = ds[b][a] = c;
  }
  int nbits = 1 << n, maxd = 0;
  memset(dp, -1, sizeof(dp));
  for (int i = 0, bi = 1; i < n; i++, bi <<= 1) dp[bi][i] = 0;
  for (int bits = 1; bits < nbits; bits++)
    for (int i = 0; i < n; i++)
      if (dp[bits][i] >= 0)
	for (int j = 0, bj = 1; j < n; j++, bj <<= 1)
	  if (! (bits & bj) && ds[i][j] > 0) {
	    int d = dp[bits][i] + ds[i][j];
	    setmax(dp[bits | bj][j], d);
	    setmax(maxd, d);
	  }
  printf("%d\n", maxd);
  return 0;
}
            
            
            
        