結果

問題 No.845 最長の切符
ユーザー kuuso1kuuso1
提出日時 2019-06-28 22:40:24
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 185 ms / 3,000 ms
コード長 1,857 bytes
コンパイル時間 3,749 ms
コンパイル使用メモリ 105,724 KB
実行使用メモリ 27,148 KB
最終ジャッジ日時 2023-09-14 22:24:46
合計ジャッジ時間 7,292 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
21,564 KB
testcase_01 AC 61 ms
23,424 KB
testcase_02 AC 61 ms
21,536 KB
testcase_03 AC 61 ms
21,596 KB
testcase_04 AC 61 ms
21,468 KB
testcase_05 AC 62 ms
23,476 KB
testcase_06 AC 61 ms
21,456 KB
testcase_07 AC 61 ms
21,664 KB
testcase_08 AC 61 ms
21,540 KB
testcase_09 AC 62 ms
21,620 KB
testcase_10 AC 65 ms
23,500 KB
testcase_11 AC 62 ms
21,524 KB
testcase_12 AC 64 ms
23,432 KB
testcase_13 AC 62 ms
21,660 KB
testcase_14 AC 63 ms
21,364 KB
testcase_15 AC 89 ms
23,816 KB
testcase_16 AC 178 ms
25,292 KB
testcase_17 AC 88 ms
21,848 KB
testcase_18 AC 117 ms
23,064 KB
testcase_19 AC 73 ms
23,512 KB
testcase_20 AC 185 ms
27,132 KB
testcase_21 AC 185 ms
25,160 KB
testcase_22 AC 87 ms
21,988 KB
testcase_23 AC 68 ms
21,436 KB
testcase_24 AC 180 ms
25,168 KB
testcase_25 AC 62 ms
21,540 KB
testcase_26 AC 87 ms
25,056 KB
testcase_27 AC 65 ms
21,544 KB
testcase_28 AC 84 ms
27,148 KB
testcase_29 AC 61 ms
19,596 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		//int Inf =(int) 1e9;
		int[][] m = new int[N][];
		for(int i=0;i<N;i++){
			m[i] = new int[N];
			for(int j=0;j<N;j++){
				m[i][j] = -1;
			}
		}
		
		for(int i=0;i<M;i++){
			m[A[i]][B[i]] = Math.Max(m[A[i]][B[i]], C[i]);
			m[B[i]][A[i]] = m[A[i]][B[i]];
		}
		
		int[][] dp = new int[N][];
		for(int i=0;i<N;i++){
			dp[i] = new int[1<<N];
			for(int j=0;j<1<<N;j++){
				dp[i][j] = -1;
			}
		}
		
		for(int i=0;i<N;i++) dp[i][1<<i] = 0;
		for(int i=0;i<(1<<N);i++){
			for(int j=0;j<N;j++){
				if(dp[j][i] == -1) continue;
				for(int k=0;k<N;k++){
					if((i >> k) % 2 == 0 && m[j][k] != -1){
						dp[k][i | (1 << k)] = Math.Max(dp[k][i | (1 << k)], dp[j][i] + m[j][k]);
					}
				}
			}
		}
		
		Console.WriteLine(dp.Select(ar => ar.Max()).Max());
		
		
		
		
	}
	int N,M;
	int[] A,B,C;
	public Sol(){
		var d = ria();
		N = d[0]; M = d[1];
		A = new int[M];
		B = new int[M];
		C = new int[M];
		for(int i=0;i<M;i++){
			d = ria();
			A[i] = d[0] - 1; B[i] = d[1] - 1; C[i] = d[2];
		}
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}
0