結果

問題 No.17 2つの地点に泊まりたい
ユーザー notetonousnotetonous
提出日時 2016-04-08 16:25:29
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 1,025 bytes
コンパイル時間 821 ms
コンパイル使用メモリ 25,824 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-05 03:45:08
合計ジャッジ時間 2,356 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 0 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 0 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 0 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 0 ms
4,380 KB
testcase_17 AC 0 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 0 ms
4,376 KB
testcase_21 AC 0 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#define INF 100000000
int N;
int s[50];
int M;
int adj[50][50];
int dp[50][50];
int MIN(int a,int b){
  if(a<b)return a;
  else return b;
}
int MAX(int a,int b){
  if(a<b)return b;
  else return a;
}
int main(){
  int i,j,k;
  int a,b,c;
  int min=INF;
  scanf("%d",&N);
  for(i=0;i<N;i++)scanf("%d",&s[i]);
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      adj[i][j]=INF;
      if(i==j)adj[i][j]=0;
    }
  }
  scanf("%d",&M);
  for(i=0;i<M;i++){
    scanf("%d %d %d",&a,&b,&c);
    adj[a][b]=c;
    adj[b][a]=c;
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(i==j)dp[i][j]=0;
      else if(adj[i][j]==0)dp[i][j]=INF;
      else dp[i][j]=adj[i][j];
    }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      for(k=0;k<N;k++){
	dp[j][k]=MIN(dp[j][k],dp[j][i]+dp[i][k]);
      }
    }
  }

  for(i=1;i<N-1;i++){
    for(j=i+1;j<N-1;j++){
      min=MIN(min,dp[0][i]+s[i]+dp[i][j]+s[j]+dp[j][N-1]);
      min=MIN(min,dp[0][j]+s[j]+dp[j][i]+s[i]+dp[i][N-1]);
    }
  }
  printf("%d\n",min);
  return 0;
}
0