結果
| 問題 | No.17 2つの地点に泊まりたい | 
| コンテスト | |
| ユーザー |  notetonous | 
| 提出日時 | 2016-04-08 16:25:29 | 
| 言語 | C90 (gcc 12.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 1 ms / 5,000 ms | 
| コード長 | 1,025 bytes | 
| コンパイル時間 | 203 ms | 
| コンパイル使用メモリ | 22,784 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-10-15 01:33:41 | 
| 合計ジャッジ時間 | 1,135 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 27 | 
コンパイルメッセージ
main.c: In function ‘main’:
main.c:20:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 |   scanf("%d",&N);
      |   ^~~~~~~~~~~~~~
main.c:21:19: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   21 |   for(i=0;i<N;i++)scanf("%d",&s[i]);
      |                   ^~~~~~~~~~~~~~~~~
main.c:28:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   28 |   scanf("%d",&M);
      |   ^~~~~~~~~~~~~~
main.c:30:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   30 |     scanf("%d %d %d",&a,&b,&c);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~
            
            ソースコード
#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;
}
            
            
            
        