結果

問題 No.17 2つの地点に泊まりたい
コンテスト
ユーザー notetonous
提出日時 2016-04-08 16:25:29
言語 C90
(gcc 12.4.0)
コンパイル:
gcc-12 -O2 -std=c90 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,025 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 173 ms
コンパイル使用メモリ 32,984 KB
最終ジャッジ日時 2026-02-23 21:06:26
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28
権限があれば一括ダウンロードができます
コンパイルメッセージ
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);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #
raw source code

#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