結果
| 問題 | No.845 最長の切符 | 
| コンテスト | |
| ユーザー |  tenten | 
| 提出日時 | 2020-09-01 08:30:34 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,440 bytes | 
| コンパイル時間 | 1,956 ms | 
| コンパイル使用メモリ | 79,464 KB | 
| 実行使用メモリ | 63,688 KB | 
| 最終ジャッジ日時 | 2024-11-17 17:45:46 | 
| 合計ジャッジ時間 | 8,023 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 3 WA * 24 | 
ソースコード
import java.util.*;
public class Main {
	public static void main (String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	int m = sc.nextInt();
    	ArrayList<HashMap<Integer, Integer>> graph = new ArrayList<>();
    	for (int i = 0; i < n; i++) {
    	    graph.add(new HashMap<>());
    	}
    	for (int i = 0; i < m; i++) {
    	    int a = sc.nextInt() - 1;
    	    int b = sc.nextInt() - 1;
    	    int c = sc.nextInt();
    	    if (!graph.get(a).containsKey(b) || graph.get(a).get(b) < c) {
    	        graph.get(a).put(b, c);
    	        graph.get(b).put(a, c);
    	    }
    	}
    	int[][] dp = new int[1 << n][n];
    	int max = 0;
    	for (int i = 1; i < (1 << n) - 1; i++) {
    	    for (int j = 0; j < n; j++) {
    	        if ((i & (1 << j)) == 0) {
    	            continue;
    	        }
    	        int tmp = 0;
    	        for (int k = 0; k < n; k++) {
    	            if (j == k) {
    	                continue;
    	            }
    	            if ((i & (1 << k)) == 0) {
    	                continue;
    	            }
    	            if (!graph.get(j).containsKey(k)) {
    	                continue;
    	            }
    	            tmp = Math.max(tmp, dp[i ^ (1 << j) ^ (1 << k)][k] + graph.get(j).get(k));
    	        }
    	        dp[i ^ (1 << j)][j] = tmp;
    	        max = Math.max(max, tmp);
    	    }
    	} 
    	System.out.println(max);
    }
}
            
            
            
        