結果
| 問題 |
No.845 最長の切符
|
| コンテスト | |
| ユーザー |
kuuso1
|
| 提出日時 | 2019-06-28 22:40:24 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 151 ms / 3,000 ms |
| コード長 | 1,857 bytes |
| コンパイル時間 | 925 ms |
| コンパイル使用メモリ | 108,544 KB |
| 実行使用メモリ | 22,784 KB |
| 最終ジャッジ日時 | 2024-07-02 05:00:00 |
| 合計ジャッジ時間 | 3,382 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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));}
}
kuuso1